Infrastructure primitives
Distributed log - Kafka from the partition up
Why an append-only partitioned log gives ordering and replay, and what replication and consumer offsets cost.
What this board gets wrong on purpose
The tension
Ordering exists only inside a partition, and a key reaches its partition by hash(key) mod the partition count - so the partition count is fixed for the life of any key that needs ordering. Adding partitions to relieve load silently remaps keys, and for the minutes that old and new records for one order sit in two different logs, two consumers process them in the wrong order. The same hash pins a hot key (one merchant, one tenant) to one partition, and a partition is consumed by exactly one member of a group, so one key caps the whole pipeline at one thread. Durability has its own trade: acks=all with min.insync.replicas=2 on a replication factor of 3 means a single slow broker raises every produce latency, and losing two brokers in one partition STOPS writes to it rather than accepting them on one copy. Turning on unclean leader election restores availability by electing a replica that is missing acknowledged records - data loss the producer was told could not happen. And the consumer commits offsets after processing, so every crash replays a window of records: exactly-once inside Kafka is real (idempotent producer plus transactions), but the moment a consumer writes to a database or calls a payment API, idempotency is the application's job and nothing on this board does it.
Practise this as an interview
Take Distributed log - Kafka from the partition up as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
A distributed log is the answer to "how do twenty services find out that an order was placed, in order, without the order service calling each of them". Kafka, Redpanda, Pulsar and Kinesis all answer it the same way: write every event once to an append-only, partitioned, replicated log, and let each reader keep its own bookmark. The interview is rarely about the API. It is about whether you know that ordering is per partition, that an acknowledgement means "in the in-sync replica set" rather than "on a disk", and that a consumer which commits after processing will process some records twice.
What you will learn
- How hash(key) mod 96 picks a partition, and why that modulo makes the partition count a decision you make once.
- Why the producer batches for 5 ms into 64 KB batches, and how that turns 200,000 records/s into about 3,100 requests/s.
- What acks=all, min.insync.replicas=2 and the high watermark each guarantee - and the exact moment a lagging follower makes that guarantee weaker.
- Why followers PULL from the leader, and why the leader epoch exists so a returning ex-leader truncates its tail instead of keeping it.
- How a consumer group splits partitions, why it cannot split one, and what a rebalance costs a 96-partition group.
- The sizing: 240 MB/s in at peak, 720 MB/s of disk writes, 12 brokers, 104 TB local plus 41 TB tiered over 7 days.
How to read this board
- Press play: eight steps follow one record from the producer's hash to a consumer's committed offset.
- PRODUCE: the producer, the partitioner (a parallelogram, because it is a function inside the client) and the batch buffer.
- ONE PARTITION: the leader, two followers - one of them in red because it fell out of the ISR - the high watermark diamond and the KRaft controller.
- KEEP: segments, the tiered store, and compaction, which is a different retention model rather than a cleanup job.
- CONSUME: the group coordinator, two consumers - the red one owns the hot partition - the offsets log and the dead-letter topic.
- Pages 1 to 6 in order, then the DATA MODEL: brokers, topics, partitions, replicas, groups and committed offsets.
1 · Requirements
Ask these before drawing anything
- What must be ordered relative to what? "All events for one order" is a partition key. "All events, globally" is one partition and about 30 MB/s, which is a very different system. The answer is almost always per entity, and somebody has to say which entity.
- Is replay a requirement? If a new service must read the last 7 days, the log is the source of truth and retention is storage you are paying for on purpose. If not, a queue that deletes on acknowledge is cheaper.
- What does a duplicate cost? At-least-once is the default. If a duplicate charge is unacceptable, the consumer needs an idempotency key, and that is a table in the consumer's database, not a Kafka setting.
- What does a lost acknowledged message cost? This decides acks, min.insync.replicas and whether unclean leader election is ever allowed.
- How skewed are the keys? One tenant producing 40 percent of traffic turns a 96-partition topic into one partition and 95 idle ones.
- How fast must a consumer see a record? Batching and the high watermark both add latency; 10 ms end to end is achievable, 1 ms is not this design.
Functional
- Produce a keyed record to a topic; records with the same key are delivered in the order produced.
- Many independent consumer groups read the same topic, each at its own position.
- A consumer may rewind to any offset, or to a timestamp, inside the retention window.
- Retention by time (7 days) or by key (compaction keeps the latest value per key forever).
- Idempotent produce: a retried batch is never written twice.
- Transactions: a consume-transform-produce step either commits its output records and its input offsets together, or neither.
Non-functional
- 200,000 records/s sustained, 600,000/s peak, average record 1 KB.
- p99 produce latency of 15 ms at acks=all; p99 end-to-end (produce to consumer poll) of 50 ms.
- An acknowledged record survives the loss of any one broker, with no human involved.
- Losing one broker of three in a partition has no effect on writes; losing two stops writes to that partition rather than accepting them on one copy.
- Adding a consumer group costs disk reads on the brokers, not a change to any producer.
Out of scope
- Per-message routing, priorities or delayed delivery. A log has none of them; a queue built on top of it does.
- Exactly-once side effects outside the cluster. Transactions stop at the broker boundary.
- Global ordering across partitions.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 6-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 6tables38 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan
More boards
The building blocks an interview asks you to build from scratch.
- URL shortener - one write, a million reads
- Distributed cache - the ring, and what a node leaving costs
- Key-value store - quorums, and where the consistency knob sits
- Rate limiter - token bucket, and where the counter lives
- Unique ID generator - 64 bits, and two facts nobody can check
- Web crawler - a frontier, and the trap of crawling forever
- Pastebin - a blob store with a short name
- Load balancer - spreading traffic, and noticing who is dead
- API gateway - one front door for many services
- Login and sessions - who you are, on every request
- Feature flags - a config change that ships like code
- Secrets manager - the one store everything trusts
- DNS - the cache that runs the internet
- Distributed cron - exactly one runner at nine o'clock
- Background job queue - at least once, and the retry that doubles it
- Code execution sandbox - running a stranger's program
- Consensus - a leader, a log, and a majority
- Object storage - eleven nines from cheap disks