SeniorRabbitMQ
Ledger entries must stay in order per account
Eight consumers share one queue. Now each account's entries must apply in order.
The setup today
Ledger events (deposit, withdrawal, fee) are published to a topic exchange and land in one queue with eight consumers. Order has not mattered so far because each event was applied independently.
Current configuration
exchange: ledger type: topic
queue: ledger.apply type: quorum
consumers: 8 prefetch: 50What you know
- About 2,000 events a second at peak, from about 1 million accounts.
- One consumer can apply about 400 events a second.
The new requirement
A new overdraft rule makes order matter: events for the same account must be applied in the order they were published, while total throughput must stay at 2,000 events a second.
Make the call
2 questions · first-try answers earn the most XP
What a strong answer also covers
- Order must also hold on the publishing side: one account's events should come from one publisher in sequence, or carry a sequence number the consumer checks.
- Changing the number of shards moves accounts between queues; drain or use a hand-over plan, as with any re-hash.
- Skipping a failed event can break the balance math; parking the whole account is often safer than continuing.
- Make apply idempotent with the event ID, since at-least-once delivery will repeat some events.