It was a distributed system. The inventory was kept in Mongo with atomic debits and credits applied with a bus in front. SQL existed for the actual order, but inventory was managed in Mongo fine.
I'd like two of this product? Increment reserved in Mongo atomically, fire a bus message that inventory was reserved. I'd now like just one? Again atomically remove one from reserved and fire another message. Simplified of course.
Two users can't reserve the same inventory, reserving the inventory is atomic, and everyone else occurs during reconciliation. Typical distributed systems.
So you can't have exactly once semantics. When you say 'bus' I assume you mean a message broker which at best gives you at least once semantics. What happens when the message is delivered multiple times?
That's just a broker; all message handlers must be idempotent. This sometimes means storing message IDs or creating one-direction state change conduits that fail subsequent duplicate messages.
To answer that question more succinctly, nothing special happens when a message is delivered more than once.
I would assume you propagate a transaction ID or expected row version (and persist transaction histories and/or version numbers along with the inventory item row after mutation).
Comments
It was a distributed system. The inventory was kept in Mongo with atomic debits and credits applied with a bus in front. SQL existed for the actual order, but inventory was managed in Mongo fine.
I'd like two of this product? Increment reserved in Mongo atomically, fire a bus message that inventory was reserved. I'd now like just one? Again atomically remove one from reserved and fire another message. Simplified of course.
Two users can't reserve the same inventory, reserving the inventory is atomic, and everyone else occurs during reconciliation. Typical distributed systems.
So you can't have exactly once semantics. When you say 'bus' I assume you mean a message broker which at best gives you at least once semantics. What happens when the message is delivered multiple times?
That's just a broker; all message handlers must be idempotent. This sometimes means storing message IDs or creating one-direction state change conduits that fail subsequent duplicate messages.
To answer that question more succinctly, nothing special happens when a message is delivered more than once.
At least, when we didn't screw up :)
Those were fun days.
I would assume you propagate a transaction ID or expected row version (and persist transaction histories and/or version numbers along with the inventory item row after mutation).