CS PAPERS DEEP-READ · PAPER 58

Kafka: a Distributed Messaging System for Log Processing

Kreps, Narkhede & Rao · LinkedIn · NetDB 2011

中文 →

What did this paper do?

In 2011 three engineers at LinkedIn published a seven-page paper describing something they had built themselves: Kafka. It is a data highway running through the company: everything the servers notice (who clicked what, who searched for what, which machine is running hot) gets tossed onto that highway, and whoever needs it picks it up. Today, from the status of your online order to a bank's real-time fraud checks, there is a good chance Kafka or an imitator is behind it.

The pain of the old world

A sizeable website produces far more activity records — every click, refresh, and swipe — than it does "real" data like orders and accounts: orders of magnitude more. Back then there were two ways to handle it.

One was the traditional message queue, a fussy post office: every letter registered, signed for, logged as collected, then destroyed. Reliable, but the bookkeeping alone cost too much to survive that volume. The other was the log hauler: each machine piles its log files up, and on a schedule they get packed off to a big warehouse to be crunched together — the volume is fine, but a round trip takes hours, and by the time you work out "this person might want to see that," the person is long gone.

What was fast couldn't scale; what scaled wasn't fast.

The idea: not a post office, a bound volume

Kafka goes the other way: the server stops keeping anyone's books.

It writes messages into a ledger that only ever grows — each new message becomes one more line at the end, never edited, never inserted in the middle. Whoever wants to read it remembers which line they got to and picks up from there next time. Nothing disappears once read; whole sections are thrown out only when they age out (say, after seven days).

So the self-evident rule that "a message can only be taken once" is gone: search reads it, recommendations read it, reporting reads it at midnight, each with its own bookmark, none disturbing the others. A bug in your program? Wind your bookmark back a few pages and read it again.

So why is it fast?

One: it only appends at the end. What a disk hates is hunting all over for a spot; what it does best is writing straight on.

Two: the server keeps no books. "Who has read up to where" was the most annoying ledger of all — a status per message, plus an index to look them up. Handed to the readers themselves, the server has just two jobs left: append, and fetch by line number.

Three: fetching takes no detour. A reader says "give me a stretch starting at line N," and the server pushes those bytes straight from the file onto the wire, without first hauling them through its own memory.

Four: one ledger becomes many. The ledger for a topic is split into several books kept on different machines, so they can be written and read at the same time.

One honest cost: in the paper's Kafka each message is stored only once, so if that machine's disk dies outright, anything not yet read is gone forever (keeping extra copies came later).

What it brought

The "log" went from an unloved by-product to the company's main data artery: one stream sits there, anyone who wants it just taps in, and adding a new system no longer means disturbing the ones upstream. Today almost anything that talks about "real-time data" or "event-driven" architecture is built on this shape.

Remember this

Turn the message hub from "a post office keeping everyone's books" into "a ledger that only grows and expires on a schedule": the server doesn't track who read what, readers hold their own bookmarks — so it is fast, many parties can read the same stream, and anyone can rewind and replay.

Want the architecture diagram, the offset and zero-copy mechanics, and the measured numbers? → Switch to the deep read