Skip to main content
The Write-Ahead Log (WAL) is RocksDB’s mechanism for ensuring durability. Every write operation is first appended to the WAL before being applied to the MemTable, guaranteeing that no committed data is lost even if the process crashes.

What is the WAL?

The Write-Ahead Log is an append-only file that records all write operations:
  • Sequential writes for high throughput
  • Crash recovery by replaying operations
  • Durability guarantees when fsync is enabled
  • Shared across all column families
The WAL is the foundation of RocksDB’s durability. Without it, only data flushed to SST files would survive a crash.

How WAL Works

Every write operation follows this sequence:

Write Path with WAL

First, the operation is serialized and appended to the WAL file:
With sync=true, the write latency includes disk fsync time (typically 1-10ms). With sync=false, latency is much lower but recent writes may be lost on system crash.

Durability Modes

RocksDB provides different durability guarantees:

Synchronous Writes

Maximum durability with higher latency:
Latency: 1-10ms depending on storage device. Use for critical data that cannot be lost.

Asynchronous Writes

Higher throughput with relaxed durability:
Latency: 10-100μs depending on system. WAL is buffered in OS page cache and fsynced periodically.

Manual WAL Sync

Batch multiple writes, then sync:
This approach provides good throughput while maintaining durability at application-defined boundaries (e.g., end of transaction).

WAL Configuration

WAL Size Limits

WAL Archival

Keep old WAL files for backup or replication:

WAL Recovery Mode

Control how RocksDB handles corrupted WAL on recovery:

Crash Recovery

When RocksDB opens a database, it replays the WAL:

Recovery Process

RocksDB scans the database directory for WAL files:
Each operation in the WAL is replayed:
  • Puts: Inserted into MemTable
  • Deletes: Marked as deleted in MemTable
  • Merges: Applied to MemTable
Operations are applied in the same order as original writes.
After replay completes:
  • Old WAL files are deleted (unless archived)
  • New WAL file is created for future writes
  • Database is ready for reads and writes

WAL and Column Families

All column families share a single WAL:
Sharing a WAL ensures atomic writes across column families and simplifies recovery, but means WAL size is affected by writes to all column families.

Atomic Writes

WriteBatch provides atomic multi-key writes:
The entire WriteBatch is written as a single record in the WAL, ensuring atomicity even across crashes.

Disabling WAL

For non-critical writes, you can disable WAL:
Warning: Data written with WAL disabled is lost if the process crashes before the MemTable is flushed. Only use for temporary or reconstructible data.

Use Cases for Disabled WAL

  • Bulk loading: Fast initial data load, then call Flush()
  • Temporary cache: Data that can be regenerated
  • Replicas: Secondary instances that can re-sync from primary

WAL Performance Tuning

Reduce Sync Overhead

WAL Recycling

Concurrent Writes

Monitoring WAL

Get WAL Statistics

Get WAL Size

Best Practices

  1. Use sync=true for critical data that cannot be lost
  2. Batch writes with WriteBatch and sync periodically for throughput
  3. Set max_total_wal_size to prevent unbounded WAL growth
  4. Archive WALs if you need point-in-time recovery or replication
  5. Monitor WAL size and flush frequency to identify issues
  6. Disable WAL only for temporary or reconstructible data
  7. Use recycle_log_file_num to reduce file creation overhead

Next Steps

Architecture

See how WAL fits into RocksDB architecture

Snapshots

Learn about consistent point-in-time reads

Compaction

Understand when WAL files are deleted

Backup & Restore

Use WAL for point-in-time recovery