Queues vs Streams vs Pub/Sub By David Boyne
Queues vs Streams vs Pub/Sub By David Boyne
When working with event-driven architectures it’s important to know the difference between queues, streams and pub/sub. At a glance they may look similar but they are completely different.
Queues
-
Messages are put onto a queue and consumers consume the message to process them.
-
Messages are acknowledged as they are consumed and deleted after they a processed.
-
Messages can be consumed by many consumers giving you the ability to process messages in parallel also known as Competing Consumers (as seen in the Enterprise Integration Patterns).
-
An real-world example of this would be queuing at the shops. You stand in one big queue (message queue) with one cashier (consumer), that cashier is processing each shopper (message). Shops open up more cashiers (consumers) to help with the customers (messages). Similar thought process with channels, messages and queues.
-
Explore the “Point-to-point messaging” visual to dive into messaging patterns.
Streams
-
Event streams involve processing data as it happens. Event streams are a continuous flow of data that can be collected and processed in (near) real time.
-
Think of streams as a series of unbounded events (events that never end).
-
Typically, messages in streams are ordered (based on partition/topic), depending on solutions used.
-
Consumers can read events in the stream from a particular point in that topic/time.
-
Read the “Understanding Stream and Discrete Events” or “Understanding Event Streaming” visual to dive deeper.
Pub/Sub (Publish/Subscribe)
-
Consumers get their own copy of the message to process (unlike queues, where messages are pulled from the queue).
-
Consumers (subscribers) come and go, producers (publishers) produce events often without knowing downstream consumers.
-
Read the “Understanding Publish & Subscribe” messaging visual to learn more.
Extra Resources
-
Enterprise Integration Patterns - Fantastic resource to dive deeper into integration patterns, a must read if you want to learn more.
-
Enterprise Integration Patterns 2 by Gregor Hohpe - Watch this video to dive deeper into the making of a pattern language. Dive deep into messaging patterns and learn more.
-
At-most-once, At-least-once and Exactly-one delivery, what does it all mean? - Visual I created to help you understand message delivery and what it all means. Good to know to help you pick the right technology for your use case.
-
Understanding Idempotency - Here is another visual that can help, understanding idempotency. If you are building message-based applications it’s worth understanding this, this can help you plan and scale your event-driven architectures so you don’t get unwanted side effects of replaying events/messages.
-
What happens what messages/events fail? - How can you handle failures? Here is a visual to help you dive deeper and be prepared.
Explore other visuals
Want to work together?
If you're interested in collaborating, I offer consulting, training, and workshops. I can support you throughout your event-driven architecture journey, from design to implementation. Feel free to reach out to discuss how we can work together, or explore my services on EventCatalog.
EDA Visuals: The book
Join over 13,000 others learning EDA and download all the EDA visuals directly to your computer.
This book contains all the visuals in one book, you can download, read offline and explore.
Purchasing the book supports my work, but for whatever reason if the book is beyond your budget, you can download it for free here.