DEV Community

gxqwb
gxqwb

Posted on

Write-Ahead Log vs Append-Only Event Log: Two Logs With Opposite Jobs

Both structures are files that only grow. Both are written sequentially, both are read in order, and both are described as "the log." That shared vocabulary hides a deep difference in intent. One exists to make a single write atomic and durable, and it is deleted the moment its job is done. The other exists to preserve a record forever, and it is the source of truth rather than a temporary aid. Confusing them leads to systems that keep the wrong data too long or throw away the right data too soon.

A write-ahead log is a crash-recovery device that records an intended change before applying it and is discarded once the change is safe, while an append-only event log is a permanent history whose retained entries are the product itself.

That distinction determines retention, readers, ordering guarantees, and what happens when the disk fills up. It also explains why the two are often used together in the same system.

Part One: What each log is for

A write-ahead log, usually shortened to WAL, solves the torn-write problem. A database page is larger than a disk sector, so a crash can leave a page half updated. The WAL records the change as a small, sequential entry before the data page is modified. If the process dies, the database replays committed entries from the log and ignores incomplete ones. This is the foundation of atomicity and durability in almost every relational engine. Because the log is only needed until the changed pages are flushed, it is periodically truncated or recycled.
An append-only event log solves a different problem: how does a system remember everything that happened so that other systems can reconstruct state? Events are immutable business facts — an order was placed, a seat was reserved, a temperature crossed a threshold. Producers append; consumers read from an offset and never modify old records. Retention is measured in days, months, or forever. The log is not a helper for a write; it is the ledger from which derived views, caches, and downstream services are built.

The physical similarity is real. But a WAL cares about the state of one page at one instant, while an event log cares about the ordering of facts across a whole system over time.

Part Two: The cost of keeping records

Run the numbers on a busy service. Suppose a database processes 50,000 writes per second, each producing a 200-byte WAL record. That is 10 megabytes per second, or roughly 36 gigabytes an hour. If checkpointing flushes pages every five minutes, the active WAL stays around three gigabytes — small enough to keep on local NVMe and cheap to replay after a crash. Now take an event log for the same service generating 8,000 business events per second at 1 kilobyte each: about 8 megabytes a second, or 700 gigabytes a day. Keeping ninety days means roughly 63 terabytes before replication. With three replicas that is close to 200 terabytes of storage, a figure that turns retention policy into a budget line rather than a default.

These orders of magnitude explain the design split. The WAL can afford to be fast and small because it throws data away. The event log must be partitioned, compressed, and tiered to cold storage because its value grows with its history. The global stream-processing and event-streaming platform market is now measured in several billions of dollars annually, and most of that spend is really a storage bill wearing a software label.

A WAL is cheap because it is throwaway, while an event log is expensive because it is retained, so the moment you start keeping a recovery log for analysis you have quietly built a second database with none of a database's lifecycle controls.

The practical rule follows: give each log an owner and a retention policy. The WAL belongs to the storage engine. The event log belongs to the organization.

Part Three: Where each design breaks

A write-ahead log breaks when replay is slow. After a crash, a database with a large uncheckpointed WAL may spend minutes applying records before it accepts connections. Teams tune checkpoint frequency to balance recovery time against write amplification: flushing too often wears devices, flushing too rarely lengthens outages. The WAL also cannot answer business questions. It records physical changes, not intentions, and its format is private to the engine. Trying to build analytics on it is a classic mistake.

An append-only event log breaks when events are wrong. Because records are immutable, a badly designed event cannot be quietly corrected; the fix is a compensating event, and every consumer must understand compensation. Late-arriving data complicates ordering: an event about yesterday that arrives today may need to be inserted into a stream that consumers have already processed. Schemas also drift. Without versioning, a field rename breaks consumers months later. And because every consumer replays from an offset, a slow or buggy consumer can fall arbitrarily far behind, forcing the platform to retain data longer than planned.

Treating the WAL as an event source almost always fails. WAL entries are physical, engine-specific, and subject to truncation. They describe how a row changed, not why. The "why" is the part that future systems need.

Part Four: An everyday analogy

Imagine a bakery. The write-ahead log is the baker's order slip written before the bread goes in the oven: "two rye, one sourdough." If the power cuts and the baker forgets what was in the oven, the slip tells them what was supposed to happen. Once the bread is baked and sold, the slip is thrown away. Nobody keeps last Tuesday's slip to understand the bakery; it was an aid to getting through the moment.

The append-only event log is the bakery's ledger: "Tuesday, 7:04, two rye sold to the corner cafe." That line is never erased. The accountant sums it for revenue, the supply manager reads it to order flour, and the owner looks back a year later to see which bread sold in winter. The ledger is not an aid to baking — it is the memory of the business. A bakery that throws away its ledger to save paper has made the same error as a team that truncates its events to save storage.

What is actually transferable

The first lesson is to ask what a log is allowed to forget. If forgetting is the point, treat it as recovery infrastructure: keep it local, keep it short, and tune it for replay speed. If forgetting is unacceptable, treat it as data infrastructure: replicate it, version its schema, define retention explicitly, and budget for cold storage.

The second lesson is that the two patterns compose. A database writes a WAL to survive crashes and also emits business events to a durable log for everyone else. Trying to merge the roles produces a WAL that is too large to replay and an event stream that is too physical to use. Keeping them separate costs more machinery but makes each one honest about its job.

The write-ahead log and the append-only event log are both sequential files, but one is a short-lived promise that a write will survive and the other is a long-lived memory of what occurred, and a system needs to know which promise it is making before it picks a retention policy.

Name them differently in your diagrams. The wording will save you an argument during the next outage.

SOL: HCqPmPJM3NVtS6YrmVaTZYnuP8XZ2PFgQZKT94VK1LkS
Creating this takes real effort — thank you for the support.

Top comments (0)