Message ordering constrains processing to follow the sequence established by publication or channel position. It matters when later messages depend on earlier ones: processing them out of order can leave application state inconsistent or invalid. Ordered delivery alone must be paired with processing that preserves that order. section 8.3.3 section 8.3.6
Order events
A sender publishes Order Created, Order Updated, and Order Cancelled in sequence. If competing receivers process them concurrently, a delay could let a receiver process the cancellation before the creation. section 8.3.6
A partitioned channel can increase receiver throughput while preserving ordering within a shard. The sender supplies a shard key, the broker assigns the message to a shard, and each shard is assigned to one receiver in a logical receiver group. Shards can be reassigned as receivers start or stop. Processing within a shard must still respect its order. section 8.3.6
Figure 8.15 Scaling consumers while preserving message ordering by using a sharded (partitioned) message channel. The sender includes the shard key in the message. The message broker writes the message to a shard determined by the shard key. The message broker assigns each partition to an instance of the replicated receiver.
The flow shows how a shard key routes messages and how partitions are assigned to receiver instances. section 8.3.6
Ordering is scoped, not a guarantee of a single sequence across every channel. A CQRS view receiving events from different channels can see a later-published event first. Even with per-channel ordering, handlers for different aggregate instances can update the same view record concurrently; the repository must prevent lost updates, for example with locking. section 13.3.3
Events from different channels
A Customer event is published before a corresponding Order event, but a delay on the customer channel lets the Order event reach the view first. The view’s update methods must handle that arrival order. section 13.3.3
Specify ordering requirements for each channel before choosing a messaging technology. Evaluate them alongside delivery guarantees, competing-consumer support, persistence, durability, scalability, and latency. Partitioning supports concurrent receivers, but does not by itself establish ordering across channels or eliminate the need to handle duplicate messages. section 8.3.3 section 8.3.6 section 8.3 section 13.3.3
