Message Queues & Async Communication
Synchronous coupling creates chains of failure: if the email service is slow, the order service is slow. Message queues decouple producers from consumers — the order service publishes an event and returns immediately; the email service processes it when it can. This improves availability, absorbs traffic spikes, and enables independent scaling of each service.
Kafka is the dominant choice for high-throughput event streaming. AWS SQS and RabbitMQ handle task queues — background jobs, email sending, file processing. The key design decision is whether consumers need to replay events (Kafka retains messages for days) or just process once (SQS deletes after acknowledgement). Dead-letter queues catch repeatedly failing messages so they can be inspected without blocking the main queue.
Check your understanding
What does a queue buy the caller?Show answerHide answer
Answer
It can return after publish; slow consumers no longer block the request path.Kafka vs SQS-style queues — one distinction?Show answerHide answer
Answer
Kafka retains a stream for replay/consumers at their pace; many task queues delete after ack.What are dead-letter queues for?Show answerHide answer
Answer
Parking repeatedly failing messages for inspection without blocking the main queue.