Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 11

Design a partitioned, replicated log for event streaming

Expert · 50 min · Queues & streams

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

Done on paper? Compare with the worked approaches