# 5. Data Persistence & Reliability

## Overview
In industrial environments, data must be preserved even during power failures or network outages. The ASF project uses a combination of SD card storage and Non-Volatile Storage (NVS) to ensure data integrity.

## SD Card Usage (Industrial Pattern)
The SD card is used for high-volume data logging. To prevent premature wear and ensure reliability, the following patterns are followed:

| Aspect | Decision |
| :--- | :--- |
| **File System** | FAT32 |
| **Mode** | SDMMC 4-bit (for performance and reliability) |
| **Structure** | Circular time-bucket files (e.g., daily logs) |
| **Write Pattern** | Append-only to minimize directory updates |
| **Flush Policy** | Triggered on power-loss interrupt or periodic intervals |

> **Warning:** Never write small files frequently. This causes excessive wear on the SD card's flash translation layer.

## NVS (Non-Volatile Storage) Rules
The internal NVS is used for small, critical pieces of data.

| Data Type | Storage Location |
| :--- | :--- |
| **Calibration Data** | NVS (Encrypted) |
| **System Constants** | NVS |
| **Counters** | RAM (with periodic commit to NVS) |
| **System Logs** | SD Card or dedicated Flash partition |

By separating high-frequency logs from critical configuration data, the system ensures that configuration remains intact even if the logging medium fails.
