Failure is one system attribute guaranteed to happen irrespective of how well a system is designed. Databases are no exception! A database restarting

How Databases Avoid Data Loss with Write-Ahead Logs?

submited by
Style Pass
2024-11-24 12:00:03

Failure is one system attribute guaranteed to happen irrespective of how well a system is designed. Databases are no exception! A database restarting after a crash or a failure should return to its state just before crashing. Besides failure handling, the distributed databases with multiple replicas must maintain high performance and low latency. This is accomplished through a technique known as Write-Ahead Logs (WAL).

Each node in a database system keeps an append-only log file in persistent storage and every client update sent to the node is first appended to this file ( write-ahead) and later applied to the data in the database. This logging technique is called Write-Ahead Logging because the update commands are written to the logs before the actual updates on the data are performed.

WAL doesn’t hold the actual state of the data held in the database, but instead, each log entry is a copy of the client’s query or command sent to the database. Once a query is written to the log file, it is executed on the data stored in the database.

Leave a Comment