Why ordering is hard
In a single thread events have an obvious order. Across machines there is no shared clock, so events may be observed in different orders by different nodes. Systems must declare what ordering they guarantee.
Levels of ordering
- Total order means every consumer sees all events in the same single sequence. It is the strongest and the most expensive, often requiring a single serialization point.
- Partial order preserves order only between causally related events and leaves unrelated events free to interleave.
- Per key order is the common middle ground. Events sharing a key, such as one account id, are ordered, while different keys may interleave.
Partitioning for scale
Message brokers reach scale by partitioning. Each partition keeps a strict order, but there is no order across partitions. Routing by key keeps all of one entity events in one partition, giving per key order while still scaling out.
Key idea
Global total order is costly, so most systems offer per key ordering inside partitions and let unrelated events interleave freely.