Database guarantees durability using WAL, and it is possible due

Arpit Bhayani

Arpit Bhayani

Aug 23, 2024 • 1 min read


Database guarantees durability using WAL, and it is possible due to LSN ⚡

Databases dump every single operation in WAL before it is applied to the actual data, and the Log Sequence Number (LSN) is a unique identifier associated with each record added to the WAL.

LSNs are monotonically increasing enabling replicas to keep track of the replication. The master node keeps a record of the highest LSN it has written. The difference between the master_lsn and the LSN on the replica helps the database determine the Replication Lag.

Thus LSNs are what enable us to achieve and implement three critical features of any durable database, and they are

  1. recovery from failure and rebuilding in-memory state of the database
  2. asynchronous replication between master and replica
  3. point-in-time snapshots by replaying changes from WAL until desired LSN

If you are interested in knowing more about this, I have a detailed video on WAL where I covered the process in detail

give it a watch - youtu.be/wI4hKwl1Cn4

⚡ I keep writing and sharing my practical experience and learnings every day, so if you resonate then follow along. I keep it no fluff.

youtube.com/c/ArpitBhayani

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses