The physical picture
A broker is a single Kafka server process. A cluster is a set of brokers that share metadata and split partition ownership between them.
┌──────────── CLUSTER ────────────────────────────┐
│ │
│ BROKER 1 BROKER 2 BROKER 3 │
│ orders-p0 (L) orders-p1 (L) orders-p2(L)│
│ orders-p1 (F) orders-p2 (F) orders-p0(F)│
│ orders-p2 (F) orders-p0 (F) orders-p1(F)│
│ │
└─────────────────────────────────────────────────┘
L = leader replica F = follower replica
Each partition has exactly one leader replica at a time. All produce and consume traffic for that partition goes to its leader; followers exist to replicate it and to stand in if the leader dies. That is why a cluster spreads leadership around: it spreads load.
Clients connect to a bootstrap.servers list, which is only a starting point. The client fetches cluster metadata, learns which broker leads which partition, and then talks to leaders directly. You do not need to list every broker in bootstrap.servers — two or three for redundancy is enough.
The commit log mental model
Here is the idea that makes Kafka's performance and behaviour click.
A partition on disk is a set of segment files. Writing means appending bytes to the tail of the active segment. Reading means starting at a byte position and streaming forward.
partition dir/
00000000000000000000.log ← closed segment
00000000000000000000.index
00000000000000368120.log ← active segment (appends land here)
00000000000000368120.index
Consequences worth internalising:
- Sequential I/O. Appends and sequential reads are dramatically friendlier to both spinning disks and page cache than random access. Kafka's throughput comes largely from refusing to do random writes.
- The OS page cache does the caching. Recently written records are usually still in memory when consumers read them, so a healthy consumer often never touches disk. This is why Kafka brokers do not want a huge JVM heap: leave RAM to the page cache.
- Reads do not mutate state. A consumer reading a record changes nothing on the broker. That is why many consumers can read the same partition independently, and why replay is trivial.
- Deletion is by segment, not by record. Retention drops whole old segments. Kafka never hunts through a file to remove one record.
Immutability, and what "delete" means
Records are immutable once written. There is no update-in-place and no per-record delete API. Data leaves only via retention policy or log compaction (Module 4). If you need "forget this user", that is a design problem to solve up front — usually via compaction with tombstones or crypto-shredding — not an ad-hoc operation.
Who tracks progress
Not the broker, in the sense you might expect. The broker stores records and their offsets. Consumers own their position. A consumer group's committed offsets are stored in an internal topic, __consumer_offsets, and the group can move that position backwards or forwards.
This is the second superpower after decoupling: reprocessing is just resetting an offset. Deploy a bug fix, reset the group to an earlier offset, replay.
Metadata and the control plane
Something must decide which broker leads which partition and track cluster membership. Older clusters used ZooKeeper; modern Kafka uses a built-in quorum-based metadata mode (KRaft). As a developer you rarely interact with either, but two implications hold in both worlds:
- Cluster metadata changes (leader elections, topic creation) are cheap but not instant. Clients retry on
NOT_LEADER_FOR_PARTITIONand similar transient errors — this is normal, not an incident. - The number of partitions in the cluster affects metadata size and failover time. Another reason not to create partitions carelessly.
Sizing intuition
| Decision | Reasoning |
|---|---|
| At least 3 brokers | Lets you run replication.factor=3 and survive one broker loss while still having a quorum of in-sync replicas |
| Spread across failure domains | Racks or availability zones, otherwise "3 replicas" can mean one power supply |
| Modest JVM heap | The page cache is the performance story; a giant heap causes GC pauses instead |
| Fast, plentiful disk | Retention is a storage commitment; running out of disk takes a broker down hard |
Exercise: A three-broker cluster loses broker 2 entirely. Walk through what happens to a topic with replication.factor=3: which partitions change leaders, what producers and consumers experience during the transition, and why the cluster is now more fragile than before even though it is still serving traffic.