Skip to main content

Kafka Architecture Internals

Level 6: Level 6: Asynchronous & Event-Driven Systemshard35 minkafkaisrdurability

Sequential writes, page cache, and zero-copy give throughput; durability is leader/follower ISR replication where durable means acks=all + min.insync.replicas>=2 + RF3.

Not a fast queue: a replicated commit log

Kafka is a distributed, replicated, append-only commit log, and almost every property people admire falls out of that one design choice. A topic is a named log split into partitions. Each partition is an ordered, immutable sequence of records, and every record gets a monotonically increasing offset (0, 1, 2, ...). That is the entire data model: no per-message delete, no random insert, no in-place update. Producers append to the tail; consumers read forward from an offset they control.

Why it is fast

Sequential disk writes: appending to the end of a file is the one access pattern spinning disks and SSDs both love, so Kafka sustains hundreds of MB/s per broker. Page cache: Kafka writes to the OS page cache and lets the kernel flush, so recent data is served from RAM with no user-space copy. Zero-copy: on read, sendfile() moves bytes from page cache straight to the network socket without dragging them through the JVM heap. Add producer-side batching and compression (lz4/zstd, batches keyed by linger.ms and batch.size) and one cluster handles millions of events per second.

Check yourself
Kafka sustains hundreds of MB/s per broker on ordinary disks. Which combination explains it?

Durability from replication

Each partition has one leader and N-1 followers (replication factor typically 3). Followers pull from the leader and, when caught up, sit in the in-sync replica (ISR) set. Two settings decide the trade:

  • acks on the producer: acks=0 (fire and forget, can lose data), acks=1 (leader persisted, but a leader crash before replication loses acknowledged writes), acks=all (leader waits for all ISR members).
  • min.insync.replicas on the broker: the minimum ISR size for an acks=all write to be accepted. With RF=3 and min.insync.replicas=2, a write needs the leader plus one follower, so you survive one broker loss with zero acknowledged-message loss and still accept writes.
Check yourself
A producer uses acks=1. The leader persists the record and acks, then crashes before any follower replicates it. What happened to that acknowledged write?

Interview nuance: acks=all alone is not durable. If min.insync.replicas=1, "all ISR" can mean "just the leader" after followers drop out, so a leader crash still loses acknowledged writes. The durable combination is acks=all and min.insync.replicas>=2 and RF>=3.

Topic "rides", partition 3:
 offset:  0    1    2    3    4  <- append here (tail)
 record: [r0] [r1] [r2] [r3] [r4]
 Leader (broker 1) --replicate--> Follower (b2), Follower (b3)
 ISR = {1,2,3}. acks=all + min.insync.replicas=2 -> survives 1 loss.

Log segments and retention: a partition is stored as segment files that roll by size/time; old segments are deleted (time/size retention) or compacted. Tiered storage (KIP-405) offloads cold segments to S3-class object storage so retention cost decouples from broker disk. Finally, KRaft (GA, default in Kafka 4.0) replaced ZooKeeper: cluster metadata now lives in an internal Raft quorum of controllers, removing the external dependency, speeding failover, and scaling to far more partitions.

Recap: Kafka is a partitioned append-only log; sequential writes, page cache, and zero-copy explain its throughput; durability is leader/follower replication tuned by acks plus min.insync.replicas over the ISR (durable = acks=all + min.insync.replicas>=2 + RF3); retention, segments, compaction, and tiered storage govern cost and replay; and KRaft removed ZooKeeper by making metadata a Raft quorum.

Check yourself
One design choice, the partitioned append-only commit log, explains both Kafka's throughput and its replay. How?

Apply

Your turn

The task this lesson builds to.

Design a Kafka topic layout for a ride-hailing event stream at 500k events/sec: choose partition count, replication factor, and key, and explain the durability/latency tradeoffs of your acks and min.insync.replicas settings.

Think about

  1. What do acks and min.insync.replicas trade off?
  2. Why do sequential writes, zero-copy, and page cache give Kafka its throughput?
  3. What did KRaft change versus ZooKeeper?

Practice

Make it stick

A second problem on the same idea, so it survives past today.

Design the Kafka topology for LinkedIn-scale clickstream ingestion at 7 million events/sec across 3 datacenters, feeding both a real-time feed-ranking pipeline and a batch data lake, where losing a page-view event is acceptable but the cluster must never be a single point of failure. Choose partition count, replication, acks, and cross-datacenter strategy.

Think about

  1. How do you match durability to the value of each event class?
  2. Why not stretch one cluster across datacenters?
  3. What holds throughput at 2 GB/s and keeps 30-day lake retention cheap?