Skip to content
About
Main content

Which of N destinations gets this record?

Which four properties does every routing choice trade, and why is routing the hardest decision to reverse?

Transport patterns asked how a record crosses the gap between two systems. Flow control asked what happens when the rates of the two sides differ. Routing asks the question that sits between them and quietly determines both:

A destination here can be a partition of a topic, a consumer, a database shard or a cache node. Every mechanism in this article is an answer to that question, and every answer is a purchase against the same four properties. You cannot maximize all four. This table is the whole article in small form:

PropertyWhat it meansBought byPaid in
Balancethe load is uniform across destinationsrandomness, fine granularitylocality, order
Localityrelated records land togetherkeyed or range assignmentbalance (skew)
Orderthe sequence inside a scope is preservedone destination per keyparallelism
Stabilitythe assignment survives a change in the set of destinationsconsistent or uniformity, simplicity

Balance and locality are directly opposed. Perfect balance means related records are scattered. Perfect locality means the load follows the shape of your data, and your data is not uniform. That is the central tension of this article.

Two more facts decide how much this matters.

Order costs parallelism, and here it becomes a number. Earlier we saw that keeping records in order limits how much work can run in parallel. In a partitioned system this is exact: your One integer has two meanings, and they pull in opposite directions. More partitions allow more parallel consumers, but each partition is a smaller scope of order.

Routing decisions are the hardest to reverse. A batch size is a configuration change. A partitioning key is a data migration, a reprocessing job and a period in which old and new layouts must both work. If you get it wrong, you live with it for years. So it deserves more of your design time than almost anything else in the pipeline.