Interview Q&A / System Design

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How does Kafka keep messages in order, and what role do partitions play?

SHORT ANSWER

Kafka guarantees order only within a single partition. Messages with the same key go to the same partition, so ordering holds per key. More partitions give more parallelism but no global order.

Explain it simply

A Kafka topic is split into partitions, each an append-only log. Within one partition, messages have increasing offsets and are read in that exact order. Across partitions, there is no ordering guarantee.

The producer picks the partition by hashing the message key. All messages with key "order-17" land in the same partition, so events for that order (created, paid, shipped) are consumed in sequence. Different orders spread over partitions and are processed in parallel.

Consumer groups: each partition is assigned to one consumer in a group, so the maximum parallelism of a group equals the number of partitions. Extra consumers beyond that sit idle.

Design consequences:

  • Choose the key as the entity whose events need ordering.
  • Need a total global order? Use one partition and accept limited throughput.
  • Increasing partition count later changes key-to-partition mapping for new messages, which can break per-key ordering during the transition.

Example

Topic with 3 partitions, key = order id.

text
P0: order-17 created, order-17 paid, order-17 shipped
P1: order-22 created, order-22 cancelled
P2: order-35 created
Consumer group of 3: one consumer per partition
Order within order-17 is preserved; order-17 vs order-22 is not.

What to say in the interview

"Kafka orders messages per partition, not per topic. I key by the entity needing ordered events so they share a partition, and size partitions for consumer parallelism. If I need global order I accept a single partition's throughput."

#kafka#messaging

Related questions

Practise more System Design questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open System Design quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.