message-ordering

Message ordering: order is local, or it is unaffordable

Why order matters. Some message sequences are causal: create the order, then charge it, then ship it. A consumer that sees "ship" before "charge" does not have a performance problem, it has a correctness bug. So ordering is not a luxury feature of a message system; part of its contract.

Why global order is the expensive version. A total order means every participant agrees on one sequence for all messages. Establishing it requires funnelling messages through a single sequencing point, or a consensus round — throughput is capped by that point no matter how many machines are added. On top of that, "before" across machines cannot be settled by wall clocks, which disagree by milliseconds — exactly the scale at which ordering decisions are made.

The working compromise: order is promised only inside a causal group. Kafka states it plainly — order is guaranteed within a partition only. All events of one order, one account, one user carry the same key, and the partitioning rule (consistent-hashing's family) sends them to the same partition, where they are appended and consumed in send order. Across groups there is no promise, because there is no causality to protect. The boundary of the ordering guarantee is drawn by the boundary of causality in the business, not by the technology.

The shape recurs. TCP made the same deal decades earlier: sequence numbers guarantee order inside one connection, and nothing orders two connections relative to each other. A connection in TCP is what a partition is in Kafka — a small kingdom inside which order is law.

Three holes that remain, and their patches. (1) Producer retries reorder: a failed send retried after its successor landed — patched by producer sequence numbers (idempotent producers), so the broker can restore send order. (2) Parallel consumption reorders: several consumers draining one partition finish out of order — inside a partition, consumption is serial or the guarantee is void; this is why partition count caps consumer parallelism. (3) Timestamps do not order: physical clocks skew, so serious systems order by logical sequence numbers, or accept a single sequencing authority (the partition's leader).

über diesen eintrag

Einer von sijie's Wiki-Einträgen. Die KI auf dieser Site ist im selben Corpus verankert und antwortet in sijie's Stimme mit Zitaten zurück auf Einträge wie diesen — das Beantworten kostet sijie Geld, daher wartet sie hinter einem Code: zugriffscode eingeben →

message-ordering — Sijie Wang