Buses¶
In storefront, we utilize a solution called buses
to handle communication between different parts of the application in a clean and robust way. This approach encompasses handling events, queries, and commands, ensuring decoupled and efficient interactions throughout the system. Buses
implement the publish/subscribe pattern, where components can publish messages (events, queries, or commands) and other components can subscribe to receive these messages. This pattern enhances the modularity and scalability of our system by allowing allowing components to communicate indirectly and reducing direct dependencies between them.
We use three different buses for different types of the events:
- eventBus - Used to handle events that occur within an application. Events can have many listeners at one time.
- queryBus - Used to handle queries within an application. Queries represent requests for information or data retrieval. Queries can have only one listener at the time to ensure each one of them returns a single, definitive result, maintaining consistency and clarity in the system.
- commandBus - Used to handle commands within an application. Commands usually represent actions or state changes. They encapsulate all the information needed to perform an action but do not return data themselves. Commands can have only one listener at the time to ensure each one of them is executed exactly once, maintaining clear responsibility and predictable behavior.