Partitions, Keys, and Ordering
Give a real production-style example of using Partitions, Keys, and Ordering. Walk through the scenario end-to-end.
Answers use simple, clear English.
Audio N/AQuick interview answer
Scenario: Order events keyed by orderId so all status updates for one order stay ordered. Implementation notes: Choose key for locality; monitor per-partition lag; plan partition count upfront.
Detailed answer
Scenario: Order events keyed by orderId so all status updates for one order stay ordered. Implementation notes: Choose key for locality; monitor per-partition lag; plan partition count upfront. Core: Ordering guaranteed per partition only. Key determines partition hash — same key → same partition. More partitions = more parallelism but more overhead. Real-time example: Order events keyed by orderId so all status updates for one order stay ordered. Pros: Horizontal consumer scale; replay by offset. Cons: Cross-partition ordering impossible; hot keys imbalance partitions. Common mistakes: Assuming global order; too few partitions limiting throughput. Best practices: Choose key for locality; monitor per-partition lag; plan partition count upfront. Audience level: Junior.
Full explanation
Ordering guaranteed per partition only. Key determines partition hash — same key → same partition. More partitions = more parallelism but more overhead.
Real example & use case
Order events keyed by orderId so all status updates for one order stay ordered.
Pros & cons
Pros: Horizontal consumer scale; replay by offset. Cons: Cross-partition ordering impossible; hot keys imbalance partitions.
Common mistakes
Assuming global order; too few partitions limiting throughput.
Best practices
Choose key for locality; monitor per-partition lag; plan partition count upfront.
Follow-up questions
- How would you test Partitions, Keys, and Ordering?
- What metrics prove Partitions, Keys, and Ordering is healthy in prod?
- How does Partitions, Keys, and Ordering change at 10× traffic?