Design a distributed message queue (like Kafka)
You build the broker itself: a cluster that takes messages from thousands of producers and keeps each one in order within its partition. It copies every message across zones and lets any number of consumer groups read it at their own pace for a week. Picture a newspaper's archive, where each edition is filed in order and every reader keeps a bookmark of her own.
It's also asked as "design Kafka", "design a pub/sub system" or "design a distributed log". If the interviewer means a work queue with acknowledgements per message, like SQS, the consumer side changes, and a follow-up below covers it (Message queues vs event streams). The closest case study is the Key-value store, which also replicates partitions under leaders. Interviewers like it because "use Kafka" answers nothing when Kafka is the question (Build vs buy). This page assumes Kafka from the ground up and spends its time inside the broker.
Below is a full mock interview following the seven steps of the framework. You're the candidate: at each Guess before you read on, stop and answer first.
Step 1 · Clarify the features and cut the scope
Minutes 0–5 · How this step works
Interviewer: Design a distributed message queue like Kafka.
You: Do consumers read a shared log at their own position, or does each message go to one worker and get deleted once acknowledged?
Interviewer: A shared log, read by many consumer groups.
You: Order: across everything, or per key?
Interviewer: Per key.
You: How long do we keep messages, and can consumers rewind?
Interviewer: A week, and yes, they replay.
You: Exactly-once processing, transactions, a schema registry?
Interviewer: Leave those out.
You: Then I'll cover topics split into partitions, produce and fetch, replication and leader failover, the controller, consumer offsets and retention. Out: transactions, schemas, stream processing and copying between regions, unless we have time. OK?
Interviewer: Go ahead.
Each answer shapes the design. A shared log means consumers keep offsets instead of the broker deleting messages. Per-key order means one leader per partition, and a week's replay makes disk the thing we size.
Step 2 · Non-functional requirements
Minutes 5–8 · How this step works
You: Say 2 million messages a second at peak, about 800,000 on average, at ~500 bytes each. A produce is acknowledged within 20 ms at p99, and a consumer that keeps up sees a message within 100 ms at p99. Producing is 99.99% available. An acknowledged message survives losing any broker or a whole zone. Order holds within a partition, and messages stay 7 days.