Data and Knowledge SystemsIngestion and freshnessPrincipal
Why can keyed Kafka updates arrive out of business order, and how should a projection reject stale state?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A customer changes from Basic to Pro and then to Enterprise. A downstream projection applies Enterprise and later overwrites it with Pro. Kafka messages use the customer ID as their key, but the topic or producer configuration may have changed and processing is asynchronous. Investigate the possible causes without assuming one. Design stale-write protection and explain what ordering information is needed during a partitioning change.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
A key helps choose a Kafka partition. It does not by itself prove the business order in which an external projection commits updates. Kafka orders records within a partition, while producers, routing changes and asynchronous sink work can introduce different boundaries. First determine which order was actually lost.
One possible cause is a partition-count change: the older keyed event may be in one partition, while a producer using the new partitioning maps the same key elsewhere. Each partition remains ordered, but there is no total order between them. Another possibility is that records were consumed in order from one partition and asynchronous workers completed their writes in reverse. Inspect producer ordering and retry settings too. Kafka’s documentation states the per-partition boundary, and its operations guidance warns that added partitions can change key placement. The prompt alone cannot establish which cause occurred.
I would inspect topic partition counts over time, producer partitioner versions, message keys, source revisions, partition and offset of both events, and the order of successful writes to the projection. A later arrival is not necessarily a later business state. Source timestamps alone can be unreliable if clocks differ or retries reuse payloads. If the source owns a monotonic per-entity revision or a comparable change-log position, carry it with each event and make the sink update conditional: apply revision 12 only if the stored revision is below 12. The exact ordering field must come from the same source authority for both events. Kafka offsets from different partitions are not directly comparable. For a hypothetical source revision 12 followed by 13, the sink must atomically apply 13 only over an older accepted revision, then reject a late full-state revision 12. A separate read followed by an unconditional write is still vulnerable to two workers racing. If events are partial patches rather than full state, global stale-revision rejection can discard an independent field update. Preserve source order, reconstruct complete authoritative state, or use a justified per-field version protocol.
What if we cannot change the producer or source? Freeze the partitioning scheme for the ordered stream, introduce an explicit repartitioned topic by stable key with a controlled cutover, or serialize updates through a stateful authority. But a new topic alone cannot retroactively infer the order between in-flight events from old and new partitions. You need a source version, a drain barrier, or a source-of-truth reconciliation. The projection should expose stale-write rejection and lag metrics, with a repair path for entities already overwritten.
Test a partition expansion while one old update is delayed, then deliver the newer update first. Check the final state and source revision, not just the order in one consumer log. One database transaction updated two tables. Why did the AI report see only half of it? asks whether one source transaction is applied partially across tables. This question is about two valid updates to one entity whose business order was lost through producer behavior, routing changes or asynchronous projection writes.
Related questions
Keep practising data and knowledge systems
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux