Queues and pub/sub are another way of communication between applications.
Imagine some sort of jar, someone puts there a paper with text, then another person comes and takes it.
So, this is the main idea of queues, publisher puts some message into the queue, then subscriber reads it. Without any doubt we can configure the whole process according to the following parameters
- How many times message could be read
- Who can publish messages
- Whether the messages should be logged
- etc
- But for now it is not that important
so, what's the difference?
| Feature | Message Queue (MQ) | Publisher-Subscriber (Pub-Sub) |
|---|---|---|
| Concept of Message | Messages generally have a specific destination. | Messages, also known as events, are sent to multiple subscribers. |
| Message Delivery | Messages are delivered to one consumer. | Messages are delivered to all subscribers. |
| Event Retry | Support exists, with the use of a dead letter queue. |
Depends on the queue implemented under the hood. |
| Memory | Requires significant amount of memory. | Requires less memory as messages are discarded post distribution. |
| Reliability | Higher, thanks to the acknowledgement concept. | Lower, due to lack of acknowledgment. |
| Throughput | Lower, due to the processing of a single message at a time. | Higher, as multiple messages can be processed parallelly. |
| Common Usage | Task distribution, load balancing. | Multi-casting events, data streaming. |

