Skip to main content

Question 20 of 50

Does Kafka guarantee global ordering?

Mid-levelSeniorTech Lead

Question

"Does Kafka guarantee global ordering across every message in a topic?"

What the interviewer wants to assess

This is the classic Kafka trap question. It tests whether the candidate answers "yes" reflexively (wrong) or understands the partition caveat well enough to answer precisely.

Resposta rápida

No. Kafka only guarantees ordering within each partition. A topic with multiple partitions has no global order between them — two messages on different partitions have no defined ordering relationship, even if they were written milliseconds apart.

Resposta nível Sênior

"Ordered" isn't a binary property of the topic — it's a property of each individual partition. If a topic has a single partition, it does have total order, because there's only one sequence. But as soon as the topic has more than one partition (the common case in production, to enable parallelism), global order stops existing by design: they're multiple independent logs, each with its own offset clock. The only guaranteed order is between messages sharing the same key, because the key pins the message to a single partition (Chapter 4). This is a deliberate design choice — trading global ordering for parallelism — not an accidental limitation.

In-depth explanation

See "Ordering within a partition — and the absence of global ordering" in Chapter 4.

Exemplo financeiro

A "purchase approved" event for customer A and a "purchase approved" event for customer B, published almost simultaneously on different partitions, have no ordering relationship between them — which is perfectly acceptable, because events for different customers have no real dependency on each other.

"Yes, Kafka guarantees ordering, it is a queue"

This answer completely ignores the effect of partitions. It's exactly the kind of answer that reveals the candidate doesn't understand Kafka's internal structure — they just memorized that "messaging implies order."

Pode vir a seguir

Likely follow-ups: "and if I needed real global ordering, how would I do it?" (answer: a single partition, accepting the cost of losing parallelism) and "what is a Consumer?".

Related chapters