QA
Intermediate LevelSystem Design & Architecture

What is a Write-Ahead Log (WAL) and how does it guarantee database crash recovery?

❓ Interview Prompt: Explain Write-Ahead Log (WAL), append-only disk logging, Log Sequence Numbers (LSN), and restoring database state after crashes.

A Write-Ahead Log (WAL) (or Redo Log) guarantees database transaction durability ($D$ in ACID):

How WAL Guarantees Durability:

1
Before modifying in-memory data pages, the database engine appends the change sequentially to the WAL file on disk.
2
Writing to the WAL is fast because disk append operations require zero random seek overhead.
3
If the server loses power, the database engine replays committed WAL entries upon reboot to restore full data state!

Code Implementation Example

sql
-- Inspecting PostgreSQL Write-Ahead Log (WAL) status
SELECT pg_current_wal_lsn(), pg_walfile_name(pg_current_wal_lsn());
πŸ’‘Querying PostgreSQL Write-Ahead Log (WAL) position.
🎯 Interview Key Takeaway

Write-Ahead Logs guarantee durability by ensuring data modifications are written sequentially to disk before memory pages are updated.

#System Design#WAL#Write-Ahead Log#Databases#Intermediate
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?