A retailer records an order, a change to its address and a cancellation. Another system reads those events and updates a dashboard. When the cancellation appears before the address change, the team asks whether the event stream is broken. The answer depends on which records were placed in which partition, how they were consumed and what the application did after reading them.
Apache Kafka stores records in topic partitions, and the log has an order within each partition. That is not a single global order across all partitions of a topic. Kafka’s design documentation describes the partition as the unit used to distribute a log and assign work to consumers. A record’s position in one partition cannot by itself tell you whether a record in another partition happened first in the real world.
The distinction sounds abstract until a business relies on a sequence. An inventory update, payment notification or customer preference can be valid in isolation and misleading when applied in the wrong order. Before changing infrastructure, decide which events truly need an ordering relationship and which can be processed independently.
One topic, several ordered logs
A topic is a named stream of records. It can have multiple partitions, each with its own ordered sequence. A record receives an offset within its partition; the offset identifies a position in that partition’s log. Offset 42 in partition zero is not earlier than offset 43 in partition one simply because 42 is smaller. The numbers belong to different sequences.
Imagine a fictional order-events topic with three partitions. Events for order A are written to partition zero at offsets 10, 11 and 12. Events for order B go to partition one at offsets 30 and 31. A consumer can read A’s records in the order of their positions in partition zero. The offsets alone do not establish whether A’s offset 11 occurred before or after B’s offset 30. An application that needs a combined timeline must define what time and ordering evidence it will use.
Log order is also not necessarily the same as the order in which actions happened in a shop, a customer’s browser or a different database. Producers may observe events at different times, retry or be delayed. If two separate systems disagree about when an event was created, a single log position does not magically resolve their clocks. Carry the identifiers and business sequence information the consuming application actually needs.
Keys help, under a specific routing rule
Applications often use a record key to route related events. If the producer’s partitioning configuration consistently maps the same order identifier to the same partition, the events it sends for that identifier can share a partition log. That can make a per-order sequence easier to process without requiring every order in the business to wait behind one global queue.
The condition matters. A custom partitioner, an explicit partition choice, multiple inconsistent producers or a change in the number of partitions can affect where records go. Do not infer that identical-looking customer IDs always landed together without examining the actual producer and topic configuration. Even when routing is stable, simultaneous independent producers can still raise the question of which event the business considers first.
Consider an order that is created, modified and canceled. A stable order ID may be a useful key. A region name might distribute those events by geography but place many unrelated orders together, creating a busy partition. A random key could spread load but fail to keep the related order events together. Key choice is a tradeoff between the sequence the application needs and how evenly work is distributed.
A consumer group shares partitions
Consumers can cooperate in a group. Kafka assigns subscribed partitions among group members; under the group assignment model, a partition is assigned to one member of that group at a time. More members can increase concurrency when there are unassigned partitions to give them, but adding workers does not split one partition into two ordered streams. The Kafka design guide explains the relationship between partitions and group consumption.
In a simplified example, a topic has four partitions and one consumer group has two healthy instances. Suppose the assignment gives each instance two partitions. If the group grows to four instances and its assignment gives each one a partition, four partitions can be read concurrently. A fifth instance subscribing only to that topic may have no partition assigned. This is an illustration of assignment capacity, not a promise that four workers will process four times as many orders.
A consumer may also subscribe to multiple topics, and assignment depends on the actual group and configuration. Separate groups can read the same topic for different purposes, such as an operations dashboard and an accounting pipeline. Their progress is tracked separately. Confirm the group name before comparing lag or assuming one team’s reader is holding up another.
Reading order is not completion order
Suppose one consumer receives A’s create event followed by its cancel event. If its application dispatches both to independent workers and the cancellation finishes first, the downstream database may see a different completion order from the log. Kafka’s partition ordering does not automatically serialize work after the application has handed it away.
The same concern appears when a consumer calls a remote service, writes a database row or queues a task elsewhere. A request can fail, time out or complete after a later request. An application may need a per-key sequence check, a conditional update, controlled worker concurrency or another design appropriate to its data. The right choice depends on what should happen when an older update arrives late, not on a blanket claim that one library setting fixes all ordering.
Use a small test with the actual handler: introduce a deliberate delay in the earlier event, process a later one and inspect the resulting state. Do this in a safe test environment with fictional records. The test should check the final business result, not merely the order in which the consumer logged receipt.
Offsets mark progress, not proof of a business result
A consumer can commit offsets so the group has a recorded position from which it can resume. Kafka’s offset-tracking description explains that commits may be automatic or controlled by the consumer. A committed offset is a checkpoint in the stream; it does not independently prove that a payment, email or database change completed correctly.
Imagine a handler commits a position and then crashes before its separate database write completes. Depending on the design, a restart may not repeat the unfinished work. Reverse the sequence and crash after the write but before the commit: the same record may be read again. These are illustrations of a boundary between systems, not a claim that every Kafka application has the same delivery behavior.
Design the side effect and checkpoint together. A stable event identifier, an idempotent operation or a transaction pattern can help when used correctly, but the choice must fit the systems involved. Our guide to idempotency keys explains the related problem of recognizing a retry. Test the failure at the exact boundary your application uses, including what happens when the downstream service succeeds but its response is lost.
Rebalances and hot partitions change the picture
When group membership or assignment changes, partitions can move among members. During that transition, the application must handle its work, commits and shutdown behavior correctly. A temporary rise in lag during a rebalance does not by itself identify the cause; it is a signal to examine group events, processing time and the state of the affected partitions.
One partition can also receive far more work than the others. If a single large customer accounts for most messages under a key, adding consumers may leave that hot partition busy while other consumers have spare capacity. Measure record rates, processing latency and lag per partition, then look at key distribution and handler cost. A topic-wide average can hide the single sequence that is falling behind.
Increasing partition count or changing a keying rule is a design change, not just a speed switch. Check how the producer assigns keys, how the application handles old and new records, and whether ordering assumptions survive the transition. A controlled test and migration plan are more useful than assuming every consumer will see the same mapping afterward.
Make the guarantee a question you can test
Write down the business entity that needs an ordered history, the key used to identify it, and the producer rule that sends its records to a partition. Then identify where the consumer can run work concurrently, where it records progress and what it does on retries. Include each downstream write in the diagram. If an event can be repeated or arrive after a newer event, state the intended outcome explicitly.
Finally, verify with representative failures: a restarted consumer, a slow downstream call, an assigned-partition change and a duplicate record. Observe both the stream positions and the resulting business state. The useful guarantee is the one the whole path actually preserves, from producer to the place where a customer or employee sees the result.
Explore Infinite Upside
For Vijay Sheth’s personal accounts, read Infinite Upside: Building Wealth With Room to Live, published by Sheth Capital, Inc.
Explore a related guide
How do idempotency keys make API retries safer?