← Lessons

quiz vs the machine

Platinum1720

System Design

Ordering Within A Partition

Why order is guaranteed only inside a partition and how keys preserve it.

5 min read · advanced · beat Platinum to climb

The scope of ordering

A broker guarantees order only within a single partition, not across the whole topic. Each partition is an append only log, so messages in it are consumed in the exact sequence they were written. Across partitions there is no global order.

Keys decide placement

A producer chooses a partition by hashing a message key. All messages with the same key, say one user id, land in the same partition and therefore stay ordered relative to each other. Picking a good key is how you get the ordering you need.

What can break order

  • Retries with in flight requests: a retried earlier message can land after a later one unless max in flight is one or idempotence is enabled.
  • Repartitioning: changing partition count rehashes keys, breaking continuity for existing keys.

The throughput tension

Strict global order would force a single partition and kill parallelism. Per key ordering across many partitions is the practical compromise: order where it matters, parallelism everywhere else.

Flow

Key idea

Order holds only within a partition; hashing a stable key keeps related messages ordered while many partitions preserve parallelism.

Check yourself

Answer to earn rating on the learn ladder.

1. At what scope does a broker guarantee message order?

2. How do you keep messages for one user ordered?

3. Why not simply guarantee global ordering across a topic?