What is a message queue, and why would you use one?
EasyConceptMessage Queues & Event Streaming
Answer
A message queue is a durable buffer between services: producers append messages, and consumers take them off and process them asynchronously. Common examples are RabbitMQ, Amazon SQS and Kafka.
- Decoupling: the producer does not need to know who consumes a message or whether the consumer is currently running.
- Load levelling: a spike of requests is queued and drained at a steady rate instead of overwhelming a downstream service.
- Reliability: messages persist until acknowledged, so failed processing can be retried; messages that fail repeatedly move to a dead-letter queue for inspection.
- Scaling: adding consumers increases processing throughput.
- Cost: extra latency, eventual consistency and another system to operate, so avoid a queue when the user needs the result immediately.
More in Message Queues & Event Streaming
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What is a message queue, and why would you use one? | Concept | Easy | Read the answer to What is a message queue, and why would you use one? | |||
| 2 | What is the difference between a message queue and a publish-subscribe system? | Concept | Medium | Read the answer to What is the difference between a message queue and a publish-subscribe system? | |||
| 3 | What do at-most-once, at-least-once and exactly-once delivery mean? | Concept | Medium | Read the answer to What do at-most-once, at-least-once and exactly-once delivery mean? | |||
| 4 | How does Kafka achieve high throughput, and how does it preserve message ordering? | Concept | Hard | Read the answer to How does Kafka achieve high throughput, and how does it preserve message ordering? |