Back to notes
QUEUES & ORDERING

Message ordering is a myth

Your messages are not in order. They never were.

The Promise

Kafka guarantees ordering within a partition. SQS FIFO guarantees ordering within a message group. Both of these are true. Both of these are useless.

The Reality

User clicks "submit." Request hits load balancer. Load balancer picks a server. Server processes request. Server publishes message. Message goes to partition based on key. Consumer picks up message. Consumer processes message. Consumer updates database.

At which point in this chain was "ordering" guaranteed?

The Example

User updates their email. Then updates it again. Message 1: email = "old@example.com". Message 2: email = "new@example.com". If Message 2 gets processed first (different server, faster network, whatever), user ends up with old email.

The Solution

Vector clocks. Lamport timestamps. CRDTs. Or: just put a timestamp in the message and let the consumer decide. Last-write-wins is a policy, not a bug.

The Truth

Ordering is a property of the observer, not the system.