What is Event Bus, Message Queues, and Message Brokers in System design.
System design is an interesting aspect of developing a system. To get somewhere, you have to know the path and the direction. Just like thinking and considering all aspects before coding a solution is vital, System design is vital for robust and highly available systems.
Event bus, Message Queues, and Message brokers are some of the infrastructures used in system design. Their understanding and why we need them is crucial. After going through multiple articles trying to explain the terms, a feeling that something was missing was incessant.
Message Queues.
It is designed to hold messages until a consumer service can process them. Use of point-to-point or producer-consumer communication model. One-to-one. The senders deliver the message and wait for acknowledgment.
When to use it:
Decoupling producer and consumer services.
Asynchronous processing of tasks.
Examples:
Order processing: Queue orders for one-by-one processing.
Data ingestion: Collect data at high velocity and process it when possible.
Event bus.
Designed for publishing events to many subscribers, Publish-Subscribe (pub-sub), one-to-many. The publishers and the subscribers don't need to know about each other. High level of decoupling. Generally, the systems consume messages as they arrive instead of storing them. It does not guarantee delivery.
When to use it:
Real-time notifications across many subscribers.
Situations where many services need to react to specific events.
Examples.
Inventory System: Notify other services when a product is out of stock.
Monitoring system: Alert other departments when the system exceeds a certain threshold.
Message brokers.
A robust system that includes the features of both Event Bus and Message Queue. Pub-sub and Point-to-Point. Can be One-to-one, One-to-many, or many-to-many.
When to use it:
Complex data routing scenarios.
Many communication patterns within a single application.
Transformation and aggregation of messages.
Examples:
Multi-service orchestration: Coordinate tasks among various microservices using complex routing rules.
Thank you for your time and see you in the next.
Special shoutout to @rauljunco on X(Formerly twitter).