SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 11
Design a partitioned, replicated log for event streaming
Dozens of teams publish events such as orders placed, payments settled and profile changes, and many other teams read them, each at its own pace. A new team should be able to start reading from a week ago, and a team that ships a bug should be able to rewind and reprocess.
Requirements
- Producers append records to a named topic, optionally with a key. Records with the same key are read in the order they were written.
- Consumers in a named group share the work of a topic, each record handled by one member, and resume from where the group left off after a restart.
- Any group can rewind to an earlier offset or timestamp and replay.
- Records are kept for a configured time per topic and then deleted, regardless of whether anyone read them.
Constraints and assumptions
- 300,000 records per second written at peak, averaging 1 KB each. About three consumer groups read each record.
- Retention is 7 days. Replication factor is 3 within one region.
- An acknowledged write must survive the loss of any one broker.
- Produce latency under 20 ms at p99 in normal operation. A broker failure may cause a few seconds of unavailability for its partitions.
- Topics have up to 1,000 partitions; a cluster runs a few thousand partitions in total.
Out of scope for the first sketch
Stream processing operators such as joins and windows · Cross-region replication · Schemas and serialization formats · Per-message acknowledgement and dead-letter routing
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a partitioned, replicated log for event streaming
Finish your first sketch before answering these. Cross out freely.
- A consumer crashes after processing a batch but before committing its offset. What does the next owner of that partition see, and what must downstream code assume?
- One customer account produces 30% of all traffic, and its events must stay in order. What happens to its partition, and what can you do?
- A partition leader acknowledges a write and dies a moment later. Walk through what guarantees the write survives, and what the producer's acknowledgement setting trades away.
- A network partition isolates the old leader, which keeps accepting writes while a new leader is elected. How do you stop two leaders from both appending to the same partition?
- A team asks for one global order across all partitions of a topic. What would that cost, and what would you offer instead?
Compare afterwards: worked approaches and reading at sketchbook /questions/distributed-log/review