Quick revision
The short answer
I would start by asking each consuming service what order it really needs, because most need order per entity, such as per customer, and not one global order. Then we move to a new topic keyed and partitioned by entity, adapt the few consumers that compare across entities to use versions, timestamps or sequence numbers, and migrate with a period of dual publishing and a team-by-team cutover. The new, narrower guarantee is written into the topic contract.
What to remember
In this answer, we saw that a single-partition topic is capped at one partition's throughput, and that removing the cap means changing a guarantee. We started by auditing what order each consumer needs, which is usually per entity, moved to a topic keyed by entity, adapted cross-entity consumers to use timestamps, versions or source sequence numbers, migrated with dual publishing and per-team cutover, and wrote the new guarantee into the topic contract.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would start by asking each consuming service what order it really needs, because most need order per entity, such as per customer, and not one global order. Then we move to a new topic keyed and partitioned by entity, adapt the few consumers that compare across entities to use versions, timestamps or sequence numbers, and migrate with a period of dual publishing and a team-by-team cutover. The new, narrower guarantee is written into the topic contract.
Why this question is asked
A single-partition topic is the only way to get total order in Kafka, so teams sometimes choose it early, when traffic is small and global order seems free. Years later the topic is at the limit of what one partition and one consumer can handle, and every service has quietly come to depend on that order. Interviewers ask this leadership scenario because changing it is mostly about people and contracts, not configuration. In this answer, we will see why a single partition caps throughput, find out what each team really needs, design the keyed replacement, handle the rare true cross-entity case, and plan the migration and the new contract.
1Why One Partition Is a Hard Ceiling
Kafka orders records only within a partition. A topic with one partition therefore has a single global order, but it also has one leader broker handling all writes and, within each consumer group, only one consumer reading. Every consumer group processes the whole stream on a single thread of work. When that thread cannot keep up, there is no setting to add a second one without splitting the partition, and splitting the partition is exactly what breaks global order.
So we are not tuning anymore; we are changing a guarantee that several services rely on. That needs a decision made with those services, not a config change pushed by the platform team.
2Find Out What Each Consumer Really Needs
The first step is a conversation with each consuming team, backed by reading their code. The question is not 'do you need order?', which everyone answers yes, but 'what goes wrong if event X for customer A is processed before event Y for customer B?'. For most consumers the honest answer is 'nothing': a search indexer, a notification service and a customer projection all need events for one customer in order, but do not care how customers interleave.
Typically a few consumers turn out to compare across entities. A fraud check might look at whether a card was used in two countries within a minute, relying on events arriving in time order. A report might assume that when it sees event 1,000 it has seen everything before. These are the cases that need a real design, and knowing exactly which they are makes the problem much smaller.
| Consumer | Order actually needed | Change needed |
|---|---|---|
| Customer projection | Per customer | None once keyed by customer id |
| Search indexer | Per customer | None |
| Notifications | Per customer | None |
| Fraud detection | Across customers, by time | Use event timestamps and a time window |
| Audit export | A complete, gap-free sequence | Use a sequence number from the source |
3Designing the Keyed Topic
The replacement topic is keyed by the entity id, for example the customer id, with enough partitions for several years of growth, say 24. All events for one customer go to one partition and keep their order, while different customers are processed in parallel. Throughput now scales with partitions and consumer instances.
Consumers that compare across entities change how they decide order. Instead of relying on arrival order, they use data in the event: a timestamp from the source for time-based logic, with a tolerance window for late events, or a version number per entity so they can ignore an older update that arrives late.
4When True Cross-Entity Order Is Required
For the rare consumer that really needs a global sequence, such as an audit export that must prove no event is missing, we put the order into the data. The source system assigns a monotonically increasing sequence number when it creates each event, for example from a database sequence in the same transaction that writes the change. Kafka no longer has to keep the order; the event carries it.
The consumer then reads from all partitions and either reorders, by buffering events until it has every number up to some point, or rejects and alerts on gaps. Buffering costs memory and some latency, so it is worth doing only for the few consumers that need it, rather than making every consumer pay through a single partition.
5Migrating Without a Big Bang
We create the new keyed topic next to the old one and run them in parallel. For a period, the producer publishes every event to both, in the same order on the old topic as before. Each consuming team then switches from the old topic to the new one on its own schedule, after testing its changes, starting with the consumers that need only per-entity order because they need no code changes.
Each cutover follows the same pattern: deploy a consumer group on the new topic starting from a known point, run it in shadow mode and compare its output with the old consumer for a few days, then switch traffic and stop the old group. When the last consumer has moved, we stop dual publishing and retire the old topic after its retention period.
- Audit what order each consumer needsmost need per-entity order
- Create the keyed topicfor example 24 partitions keyed by customer id
- Dual publish to old and new topicssame events, same ids
- Does the consumer compare across entities?YesAdd versions, timestamps or sequence checks firstNoSwitch it directly
- Shadow run and compare outputsa few days per team
- Cut over the teamstop its group on the old topic
- Stop dual publishingretire the old topic after retention
7 steps in order. Play them, or step through them one at a time.
6Writing the New Guarantee Down
The last step is easy to skip and important to do: record the decision and the new guarantee in the topic contract, the documentation that every producer and consumer of the topic relies on. It states that events are ordered per customer id, that there is no order across customers, which fields carry versions and sequence numbers, and what consumers should do with stale or late events. An architecture decision record explains why the change was made and what alternatives were rejected.
Without that, a new team in two years will assume global order again, because it was true once and nobody wrote down that it stopped being true.
7Follow-up questions
Couldn't we just make the single partition faster?
Up to a point: faster consumers, batching and better hardware buy time. But the ceiling remains one partition and one consumer per group, and traffic keeps growing. If the audit shows that almost nobody needs global order, keeping it is paying a large cost for a guarantee nobody uses.
How do you handle a team that refuses to change?
Make the cost visible and the change cheap. Show the throughput data and the date at which the single partition will no longer cope, offer help with the consumer changes, and keep the old topic running with dual publishing for an agreed period. If one consumer truly needs global order, the sequence number approach gives it that without holding everyone else back.
Does dual publishing risk the two topics disagreeing?
Yes, if the producer writes to one and fails before writing to the other. Using a transactional producer for both sends, or an outbox table that a relay publishes to both topics, keeps them consistent. Consumers in shadow mode comparing outputs also catch differences early.
8Conclusion
In this answer, we saw that a single-partition topic is capped at one partition's throughput, and that removing the cap means changing a guarantee. We started by auditing what order each consumer needs, which is usually per entity, moved to a topic keyed by entity, adapted cross-entity consumers to use timestamps, versions or source sequence numbers, migrated with dual publishing and per-team cutover, and wrote the new guarantee into the topic contract.
Open with
A single partition gives global order, but also a hard ceiling: one leader, one consumer per group, and no way to scale without splitting the partition, which breaks that order.
Then, if they want more
So this is a change to a guarantee, and I'd lead it as one. First I'd audit every consumer, asking not whether they need order, but what breaks if two different customers' events are swapped. In my experience most consumers, like projections, indexing and notifications, need only per-entity order.
A few, like fraud detection or an audit export, compare across entities, and those are the ones needing real design. Then I'd create a new topic keyed by the entity id with room for growth. Per-entity order is preserved by the key, and throughput scales with partitions.
Consumers that compare across entities switch to data in the event: source timestamps with a tolerance window, per-entity versions so stale updates are ignored, or for true global needs a sequence number assigned at the source, with the consumer reordering or detecting gaps.
For the migration I'd dual publish to both topics, ideally via an outbox, and let each team cut over on its own schedule after a shadow run comparing outputs, starting with the teams that need no code change. Finally, I'd record the decision and the new guarantee in the topic contract so nobody assumes global order again.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation, Spring for Apache Kafka reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Several services rely on strict global order of events across all customers, which...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/d78cb09767/