Video in progress
What does a message queue give a system?
A queue decouples the sender from the receiver: the sender drops off the message and leaves, and the worker picks it up at its own pace. This smooths out load spikes, takes slow work out of the main request, and keeps one service going down from taking another with it.
📖 Answer
Example: when a user signs up, you need to send them an email, write an event to analytics and grant a bonus. If you do everything inside the HTTP request, then when the mail service slows down for 5 seconds, the signup waits 5 seconds too.
With a queue: the application saves the user to the database, puts a UserRegistered message on the queue and responds right away. The mail, analytics and bonus services pick up the message on their own.
What you gain:
- speed — the user doesn't wait for slow work;
- resilience — if the mail service is down for an hour, messages wait in the queue;
- smoothing — if 10 times more orders arrive on a sale day, the workers work through them gradually.
The cost is that the system becomes asynchronous. A message can arrive twice, arrive late, or fail, and you need monitoring to see that. RabbitMQ, Kafka and AWS SQS are the most common ones.
Sign up to mark studied questions and save your progress.