SimuVedaSystem Design Lab Open in the lab

Database internals / Intermediate / 5 min / Updated

Write-ahead log: fsync, group commit and crash recovery

Commit with an fsync each time, share fsyncs with group commit, or go async, then pull the power cord and see which commits survive.

Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.

In short

What is write-ahead log?

A write-ahead log records each change and fsyncs it before the commit is acknowledged; recovery replays it.

Why does it matter?

It is what makes committed data survive crashes and power loss without writing every data page at once.

What is the trade-off?

Per-commit fsync is safe but caps throughput; group commit keeps safety; async commit risks the last moments.

How do you explain it in an interview?

"Synchronous commit with group commit on fast NVMe; async only for data we can afford to lose, like metrics."

Check yourself

When can a database safely say "committed"?

Answer: When the log record is fsynced to stable storage. After a crash the log is replayed, so anything fsynced in the log survives even if data files were not written.

What does group commit improve?

Answer: Throughput: many transactions share one fsync. fsync costs milliseconds; batching commits that arrive together spreads that cost.

What is the risk of async commit?

Answer: Commits acknowledged in the last moments before a crash are lost. The client is told "done" before the log reaches disk; a power cut loses that window.

See it happen in the simulation →

write-ahead logwalfsyncgroup commitcrash recoverydurabilitypostgresdatabase internals

More in database internals