I am trying to figure out how an AMQP broker, such as RabbitMQ, can be integrated in our architecture. This should allow to easily scale horizontally in the future.
For the sake of simplicity, let me ask the question via an analogy.
Say you have:
- A set of bank accounts. We assume that the the number of accounts can grow and shrink at any time.
- A fixed pool of workers/consumers. These workers are responsible for executing actions on a bank account, such as a withdrawal.
- A user interface, which provides the user the possibility to initiate an action, such as a withdrawal.
- An AMQP exchange.
When the user initiates a withdrawal, a message encapsulating this action is given to the AMQP exchange. The exchange puts the message in a queue, and it will be picked up by one of the available workers consuming this queue.
But what happens if the user 'immediately' initiates another withdrawal? The corresponding message might be picked up by another worker, resulting in two workers processing the same bank account simultaneously.
How do you synchronize between the workers to guarantee a happen-before relation? How do you prevent that one worker is working on the same bank account then another?
As I am fairly new to architectural design, this might be a generic question. I am happy with any external useful resource (book, ...) that might help me here.