Write-ahead Logging

Read this article first. It is incredibly well written and provides a detailed explanation of logs. Most of what is described below is distilled out of this article and enriched by further reading found in the links below.

Also knows as commit logs, or transaction logs, logs of various forms for this use case have been in use for quite a long time in computer science. They are currently one of the key components of a number of distributed and real-time architectures.

Overview of logs

Logs serve two basic sets of problems. Ordering of events and distributing events. These two problems enable State Machine Replication (explain).

Databases tend to add specificity to the action of logging and distinguish between two types; physical and logical logging. Physical logging equates to logging the values of each row that are changed. Whereas logical logging equates to the logging of the sequential SQL queries that apply said changes to the data.

Two models

  1. State Machine Model: Or an active/active model where one process keeps a log of all the incoming requests/mutations of the data and all of the replicas process each request in order from the log
  2. Primary/Replica Model: One of the replicas is elected the “Leader” and the leader processes all of the incoming requests persisting the actions to the log, from which all of the replicas read and update their state to stay insync.