# How Flash Memory affects predictability

> Flash memory is a type of persistent storage widely used in embedded and real-time systems. Over the years, various technologies have been developed for long-term information storage. In this context, “information” refers to data processed by a computer system, and “long-term” implies that the data remains intact even when power is removed, without requiring continuous energy to retain it. While storage methods such as HDDs, magnetic tapes, FRAM, and UV-erasable EEPROMs still exist, they generally lack predictable access times. As a result, systems requiring deterministic behaviour — especially real-time systems — tend to favor flash memory, which relies on the electrodynamic properties of semiconductor materials. However, the way flash memory is organized and managed introduces timing constraints that real-time databases must account for.

> ## NOR vs. NAND Flash: Choosing the Right Type for Database Storage

> Flash memory is available in two primary types: NOR and NAND, named after the logic gate structures of their memory cells. Both are non-volatile, support multiple program/erase (P/E) cycles, and require an erase operation before rewriting data. However, they differ significantly in architecture, performance characteristics, and suitability for database applications.

> NOR flash provides fast, random read access and supports byte-level addressing, making it ideal for storing firmware and executing code directly (XIP – eXecute In Place). It is also known for higher reliability, with lower bit error rates and longer endurance. However, NOR flash typically has lower storage density and slower write/erase speeds, limiting its practicality for data-intensive workloads such as real-time databases.

> NAND flash is optimized for high-density storage and block-based operations, offering significantly faster write and erase speeds and better cost-per-bit efficiency. These characteristics make it the preferred choice for applications with frequent write operations, such as logging, event capture, and embedded databases. However, NAND flash is more susceptible to wear and data corruption over time due to cell degradation and inherent manufacturing defects.

> To mitigate these issues, NAND-based systems rely on technologies focused on data integrity and flash longevity, including ECC (Error Correction Code) and CRC (Cyclic Redundancy Check) to detect and correct errors, Bad Block Management (BBM) to isolate defective memory blocks and wear leveling and over-provisioning to evenly distribute P/E cycles

> These mechanisms are essential for maintaining flash lifespan, but may introduce unpredictable access delays that must be accounted for in real-time database systems with strict transaction deadlines. The table below summarizes the key differences between NOR and NAND flash technologies

> Feature
> NOR
> NAND
> Capacity
> Low (MB to ~1GB)
> High (GB and above)
> Random Read
> Faster
> Slower
> Write Speed
> Slower
> Faster
> Erase Speed
> Slower
> Faster
> Bit-Flipping
> Less common
> More common
> Factory Bad Blocks
> 0%
> Up to 2%
> Bad Block Development
> Less frequent
> More frequent
> Bad Block Handling
> Not mandatory
> Mandatory
> Typical Application
> Code storage and execution (XIP)
> Data storage and databases

> In summary, while NOR flash is suitable for firmware and read-only storage, NAND flash is generally the better choice for database systems, particularly when frequent writes and large data volumes are involved.

> This manual focuses on NAND flash, with special attention to challenges specific to real-time database workloads.