When a write operation arrives, the database must write it to disk immediately to prevent data loss.
If we wrote sorted SSTables on every write, it would require rewriting the entire disk file—causing massive write amplification. Instead, the engine writes to the Write-Ahead Log (WAL). Because it is append-only, the write is done in a single sequential disk seek, making it incredibly fast.
Concurrently, the write is inserted into the MemTable. When the MemTable exceeds a configured size limit (e.g., 64MB in production), it transitions to a read-only state. A background worker then flushes its sorted contents into a new Level 0 SSTable file, clears the corresponding WAL, and creates a fresh, active MemTable.