All jobs / Backend developer / Distributed Systems
Backend developer interview question · 3–5 years
Order-status events for the same order are arriving out of order at the consumer. The topic has twelve partitions.
Why, and what do you change?
The strongest answer
Ordering only holds within a partition and these events were spread across twelve — key them by order id, so every event for one order lands on the same partition and one consumer reads them in sequence
Why it works
Exactly — the key picks the partition and the partition is the ordering unit. It also sets your parallelism ceiling.
What a good answer covers
- Order holds inside a partition.
- Key by the entity id.
- Same key, same partition, same order.
- Partitions cap your parallelism.
Answers that fall short
- Close, but not the strongest: Set the topic to a single partition so that everything is ordered
That does give total order, and caps throughput at one consumer; keying keeps both the order and the parallelism. - Weak: Put a timestamp on each event and sort them in the consumer before applying them
Sorting needs a window, and a window needs a deadline — you have rebuilt ordering with a guess inside it. - Red flag: Add a short delay in the consumer so the earlier events have time to arrive first
A sleep is a race you tuned once on a good day; it fails the first time a partition lags.
Who gets asked this
More Distributed Systems questions
- The interviewer asks: “The user saves a profile then immediately GETs it from another region and sees the old…
- The interviewer asks: “A dependency is failing. How do you stop your service from dying with it?” Strongest…
- The interviewer asks: “The outbox publisher crashed after sending but before marking sent. What happens?”…
- The interviewer asks: “Recommendations are down. Checkout still needs to work. What do you do?” Strongest…
- The interviewer asks: “We're adding a search index. Can the API write DB and Elasticsearch in one request?”…
- What happened, and what actually protects the write?
- The interviewer asks: “Active-active in two regions — what's the hard part?” Strongest answer?
- The interviewer asks: “A client retries POST /payments because of a timeout. How do you not charge twice?”…