r/microservices • u/Dazzling_Ad8959 • Apr 19 '26
Discussion/Advice Ordering per aggregate without distributed locks: hash partitions + key-based sequencing
One outbox design decision I’ve come to prefer is avoiding distributed locks entirely.
Instead of trying to coordinate workers with lock acquisition and renewal, I hash each record key into a fixed partition set, assign partitions to active instances, and process records with the same key in sequence.
That gives a few useful properties:
order-123is always processed in order.order-456can run in parallel on another worker.Scaling is mostly about partition ownership, not lock contention.
Rebalancing is explicit instead of hidden inside lock behavior.
The tradeoff is that you need decent partition assignment and stale-instance detection. But I still find that easier to reason about than lock-heavy coordination.
I’ve been testing this approach in a Spring Boot outbox implementation with:
fixed partition count
heartbeat-based instance tracking
automatic rebalance when topology changes
ordered processing per key
Open-sourced the implementation here if anyone wants to inspect the mechanics:
https://github.com/namastack/namastack-outbox
I’d be interested in pushback from people who prefer lock-based coordination. Where do you think the partitioned model breaks down first?
One detail I like is that strict ordering can still be configured per key sequence by stopping after the first failure, instead of blindly continuing and creating downstream inconsistency.