Why put a message queue between an order service and an email service?
Options
- To make the emails arrive much faster to users
- To decouple them; emails are handled later (Correct option)
- Queues replace the need for a real database
- To encrypt each email that is being sent out
Answer
To decouple them: the order service drops a message and continues; the email service processes it when it can, even if it was briefly down
Why
Without a queue, the order service calls the email service directly and must wait; if the email service is down, the order request fails.
With a queue (RabbitMQ, SQS, Kafka) the order service just publishes 'order created' and responds to the user immediately. The email service reads messages at its own pace and catches up after outages.
This is asynchronous communication.
Remember
Queue = decouple producer and consumer; work happens later.