A write-ahead log appends operations or state changes in order before acknowledging the write. If a worker fails, another process can replay the durable log to reconstruct the current state.
Separating the log from materialized repository state can reduce synchronous replication. The design still needs ordering, idempotent replay, retention and compaction so recovery remains correct and efficient.
ELI5
A write-ahead log saves an ordered record of changes before updating the main stored state. If the system stops unexpectedly, it can replay the saved record to finish or reconstruct the work.
For example, a database can record "increase account balance by 20" in its durable log before changing the displayed balance. After a crash, the system checks the log and applies any recorded change safely, taking care not to apply it twice.
Why is a write-ahead log useful for recovery?
A worker can replay the ordered durable records after failure instead of relying on its lost local state.
Why does a write-ahead log need compaction?
Without compaction, replay cost and storage grow indefinitely as every historical change remains in the log.

