Kafka preserves message order within a partition, not across every partition in a topic. In Go, keep related events in sequence by assigning them a stable key—such as an account ID—and configuring the producer’s partitioner to route that key consistently to the same partition. This preserves per-key order while allowing different keys on different partitions to be processed in parallel.
What ordering Kafka guarantees
A Kafka topic is made up of partitions, and each partition is an ordered log. Apache Kafka documents that messages sent by a producer to a particular topic-partition are appended in send order; consumers read records in the order stored in that partition’s log. Kafka’s ordering guarantee is therefore partition-local.
When a topic has multiple partitions, records in different partitions can be consumed at different times and in parallel. Kafka does not define a single total order across those partitions. If one event is in partition 0 and another is in partition 1, their relative consumption or processing time does not establish which came first for the topic as a whole.
How to preserve order for related events
Use a stable message key that represents the entity whose events need a shared sequence. For example, key account balance events by account ID. The producer must consistently map the same key to the same partition; then those events share that partition’s ordered log. This guarantees order for that key’s records as stored, not a total order between different keys.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
Partition assignment is a producer-side choice. A key alone is not a universal guarantee: it must be paired with a compatible key-based partitioner, and producers writing related events must use a consistent assignment strategy. Kafka’s producer documentation describes partition selection and keyed records. See the Kafka producer configuration documentation.
Configure key-based partitioning with kafka-go
In kafka-go, inspect the Writer’s Balancer setting rather than assuming a Go client default. Its Hash balancer routes records with the same key to the same partition. Other choices, including round-robin and least-bytes balancing, distribute records differently and may not keep related events together. The kafka-go Balancer documentation describes the available strategies.
w := &kafka.Writer{
Addr: kafka.TCP("localhost:9092"),
Topic: "account-events",
Balancer: &kafka.Hash{},
}
err := w.WriteMessages(ctx,
kafka.Message{Key: []byte("account-42"), Value: []byte("deposit")},
kafka.Message{Key: []byte("account-42"), Value: []byte("withdrawal")},
)
This example makes the intended partitioning strategy explicit: both events carry the same key, and the writer uses the hash balancer. Confirm the API and behavior against the version of kafka-go in your application. If you change partitioning behavior or the topic’s partition count, verify how that affects key-to-partition assignment; do not assume an existing key’s events will forever map identically after a topology or partitioner change.
Choose partition count for both ordering and parallelism
A consumer group distributes a topic’s partitions among its members. Members can process separate partitions in parallel, while each partition retains its own log order. A single partition gives the topic one partition sequence, but only one group member can actively read that partition at a time. Adding more group members than the topic has partitions does not give that group more active partition-level readers.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall| Design | Ordering scope | Parallelism implication | Best fit |
|---|---|---|---|
| One partition | One sequence for the topic’s records | At most one group member actively reads that partition | Use when a single sequence is essential and the throughput and parallelism tradeoff is acceptable. |
| Multiple partitions with stable key routing | Per key, provided related records consistently map to one partition | Different partitions can be processed in parallel | Usually appropriate when each entity needs ordered events but separate entities can proceed independently. |
| Unkeyed or distributing assignment | Partition-local only; related records may land in different partitions | Can distribute work, depending on the balancer | Use when spreading load matters more than keeping related events in one sequence. |
One partition is not the only way to preserve useful order. If the requirement is “events for each account must be sequential,” stable key routing lets different accounts use different partitions, retaining concurrency across accounts. If the requirement truly is “every event in the topic must have one shared sequence,” a single partition provides that sequence, with the associated limit on partition-level consumer parallelism.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Keep consumer processing and offset commits in order
Receiving records in partition order is different from finishing application work in that order. If a consumer hands records from one partition to concurrent workers, a later record may finish first. Committing its offset too early can move the group’s committed position past earlier work that has not finished.
Rank #4
In kafka-go, group-mode ReadMessage automatically commits offsets. For explicit control, use FetchMessage and then CommitMessages after processing. The library documents that committing the highest offset for a partition commits earlier offsets in that partition too. See the kafka-go Reader commit documentation.
- Fetch: retrieve records from the group with
FetchMessage. - Process: complete the application work for a record before treating it as safe to commit.
- Commit safely: if processing records concurrently, track completion by partition and commit only a position that does not skip unfinished earlier work when that matters to your delivery requirements.
This matters when a consumer restarts: work whose offset has already been committed will not be replayed from the group’s previous committed position. A higher offset is not an independent acknowledgment for only one message; it represents progress in that partition.
Recommended Free Tools
Quick Recap
Best Value
Checklist for an ordering requirement
- Define what must be ordered: all topic records, all events for one entity, or only records handled by a particular worker.
- For per-entity order, choose a stable key and explicitly configure a compatible key-based balancer, such as
kafka-go’sHash. - Make sure all producers of the related events use compatible key and partitioning rules.
- Choose a partition count that supports the desired consumer-group parallelism without implying a cross-partition total order.
- If processing concurrently, prevent commits from moving beyond unfinished earlier records in the same partition.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




