What Is a Log?

A staff-level study guide covering the log abstraction, data integration patterns, stream processing, Kafka internals, and geo-distributed consensus — from Jay Kreps' foundational "The Log" essay through to multi-master conflict resolution.

Jay Kreps' "The Log" essay is the single most important piece on Kafka's design philosophy. It establishes why the log is a fundamental data structure — as foundational as a hash table — and how it solves the data integration problem at organizational scale.

Logs in Databases

Originating from IBM's System R, database logs serve four purposes:

  1. Keep data structures and indexes synchronized during crashes
  2. Write information about record modifications before applying changes (write-ahead logging)
  3. Act as the authoritative source for crash recovery
  4. Enable replication via log shipping (Oracle GoldenGate, MySQL binlog, Postgres WAL)

State Machine Replication — The Core Principle

If two identical, deterministic processes begin in the same state and get the same inputs in the same order, they will produce the same output and end in the same state.

WordWhat it actually means
DeterministicThe process's output is driven only by its inputs — no thread scheduling randomness, no gettimeofday(), no external non-repeatable state.
Same stateBoth replicas start with identical data on disk/memory.
Same inputs in the same orderThis is exactly what the log provides. The log is the shared sequence of inputs.
Same output / same end stateBoth replicas end up identical — guaranteed.

The punchline: You reduce the hard problem of "keeping N machines in sync" to the simpler problem of "building a distributed log that all machines read from." Once every replica reads the same log in the same order, consistency is automatic. Bonus: the log entry number (offset) becomes a clock for replica state — you can describe any replica's state with a single number.

What Goes in the Log? Two Models

ModelWhat goes in the logWho does the work
Active-Active (State Machine)The incoming request (the transformation: "+1", "×2")Every replica executes the transformation independently
Active-Passive (Primary-Backup)The result of processing ("1", "3", "6")Only the leader executes; replicas just apply the result

Physical vs. Logical Logging

TypeLogsExample
PhysicalThe changed row contentsRow 42: {name: "alice", balance: 100}
LogicalThe SQL command that caused the changeUPDATE users SET balance=100 WHERE id=42
Operations (Logical)Results (Physical)
Log sizeSmall (one SQL statement)Large (entire changed row)
Replay correctnessDangerous — same SQL can produce different results if replica state divergedSafe — just overwrite, no re-execution
Real-world failureMySQL binlog (statement mode): INSERT ... WHERE id = (SELECT MAX(id)) produced different rows on replicasPostgres WAL avoids this entirely

Mental model: The log is the source of truth. What you put in it is your choice — operations (compact, but requires identical starting state) or results (bulkier, but safe regardless of replica state). Most real systems mix both.

The Relationship to Consensus (Paxos, RAFT, ZAB)

The goal: every replica must hold the same entries in the same order. If Server 1 says entry #42 is X and Server 3 says entry #42 is Y, the log has diverged and is useless. Consensus protocols exist to make that impossible. The easiest way to understand them is in three steps.

Step 1 — One leader decides the order

For any one log (a Kafka partition, a Raft group), exactly one server is the leader. Every client sends its writes to that leader. Whatever order the writes land in the leader's log is the order. Followers simply copy the leader's log; they never decide anything.

Client A sends X and client B sends Y, both to the single leader. The leader appends them to its log as dot dot dot, X, Y, and that arrival order is the order: there is no vote about it. The leader then ships the entries to follower 1 and follower 2, which each copy the log exactly as dot dot dot, X, Y. Followers never decide anything.
Whoever reaches the leader first goes first — followers never decide

So in normal operation there is no vote about ordering. If A and B write at the same moment, whoever reaches the leader first goes first. The WAL on each server is the result of this, not an input: each server writes the entries in the order the leader set.

Step 2 — The majority vote decides two other things

"Consensus" and "majority vote" are about what happens around the leader, not about ordering:

QuestionHow the majority answers it
Is this write committed?
(safe to tell the client "done")
Only once a majority of servers hold a copy. With 5 servers, the leader plus 2 followers.
Who is the leader?A candidate needs votes from a majority, and it is only given votes if its log has every committed entry.

Why "majority" makes this work: any two majorities overlap. Out of 5 servers, any group of 3 and any other group of 3 must share at least one server. That single fact gives both guarantees:

  • Only one leader at a time. Two candidates can't both collect 3 votes in the same election, because the shared server only votes once.
  • Committed writes survive a leader crash. The 3 servers holding a committed write overlap with the 3 that elect the next leader, so at least one voter has the write and refuses to vote for a candidate missing it.

Step 3 — The one case where order is actually disputed

Order only becomes a fight when two servers both think they are leader. Typical cause: the old leader gets cut off by a network partition, doesn't know a new leader was elected, and keeps accepting writes.

Where Paxos, Raft and ZAB fit

ProtocolWhat it agrees on
PaxosA single value ("what goes in this one slot?"). No stable leader, so competing proposers can race.
Multi-PaxosPaxos run once per slot, with a stable leader to skip the race. A numbered sequence of agreed slots is just a log.
Raft / ZABModel the leader and the log directly from the start. Same guarantees as Multi-Paxos, much easier to reason about.

Kafka's version of the same idea: each partition has one leader that orders its writes. Instead of a fixed majority, a write commits once every member of the ISR (in-sync replicas) has it, and a new leader is only chosen from the ISR. The controller that makes those choices itself runs on Raft (KRaft).

Kreps' bigger point: treat the log like a hash table, a basic building block. You shouldn't need to care whether Raft, ZAB or Paxos runs underneath. Consensus is the engine inside a distributed log; the log is what you should actually reason about.

Why This Breaks Under Pure Async Replication

If the leader acks the client immediately after its own local write, then replicates to followers whenever — that's a data-loss window. A crash between "acked the client" and "any follower got it" silently drops a write the client was told succeeded. Real systems close this by gating the client ack on quorum replication, not by making replication itself synchronous. Kafka exposes this directly as a producer setting:

acksLeader waits forDurability
0NothingCan silently lose data on leader crash
1Its own local write onlyLost if leader crashes before any follower replicates
all / -1Every current ISR (in-sync replica) memberSafe — any future leader is elected only from the ISR

Replication in Kafka is always physically async — followers pull from the leader on their own schedule. The durability guarantee doesn't come from replication being synchronous; it comes from when the leader is allowed to ack the client, gated by acks and min.insync.replicas.

Changelog 101: Tables and Events Are Dual

ConceptDefinition
LogComplete record of all changes (the events)
TableCurrent state derived from applying all log changes in order
  • Apply log changes in order → recreate any table at any point in time
  • Transform logs into derived tables and indexes
  • This is exactly how version control works: patches = log, snapshots = table