# RocksDB: Write - Cont'd

![`smart`](RocksDBWrite02_aa_001_20220511.png)

------------------------------------------------------------
RocksDB is a key-value database that uses a log-structured merge-tree (LSM tree) data structure to provide efficient writes and fast point lookups. The files on the disk are organized into multiple layers, with the most recent data being stored in the Level-0 (L0) layer. As the data in L0 grows, it is periodically compacted into larger files in the next layer (L1) and so on. This allows for efficient writes and efficient storage of data on disk.

When the write operation is performed, the data is first written to the `write-ahead logging` (WAL) to ensure durability. And then, it is added to the in-memory MemTable. The data in the MemTable is periodically flushed to disk in the form of sorted string tables (SST files), which are organized by key. This allows for fast point lookups and efficient disk storage.

When the delete or update operation is performed, a flag is added to the MemTable to indicate that the key has been deleted or updated. This flag is used to filter out the deleted or updated keys when performing read operations. The actual deletion or update is performed during the compaction process, when the MemTable data is merged into the SST files on disk.

In summary, RocksDB uses a combination of WAL for durability, MemTable for efficient writes, and LSM tree for fast point lookups and efficient disk storage to provide efficient and reliable CRUD operations.