From b87fa207187f9b2171e75180ee43c938a346def7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 15 Nov 2024 13:49:11 +0300 Subject: [PATCH] Added event bus guiding section --- .../infrastructure/event-bus/index.md | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/en/framework/infrastructure/event-bus/index.md b/docs/en/framework/infrastructure/event-bus/index.md index 982268780a..1c3f59bc4e 100644 --- a/docs/en/framework/infrastructure/event-bus/index.md +++ b/docs/en/framework/infrastructure/event-bus/index.md @@ -6,5 +6,26 @@ An event bus is a mediator that transfers a message from a sender to a receiver. ABP provides two type of event buses; -* **[Local Event Bus](local)** is suitable for in-process messaging. -* **[Distributed Event Bus](distributed)** is suitable for inter-process messaging, like microservices publishing and subscribing to distributed events. \ No newline at end of file +* **[Local Event Bus](local/index.md)** is suitable for in-process messaging. +* **[Distributed Event Bus](distributed/index.md)** is suitable for inter-process messaging, like publishing and subscribing to distributed events in a distributed/microservice system. + +## Event Bus Guiding + +You may confuse which event bus to use in your application. Here, a few example scenarios: + +* If you are building a microservice system, use the distributed event bus for **inter-microservice communication**. If you are publishing an event and always handling it in the same microservice, you can use the local event bus for that event. +* If you are building a modular monolith application, use the distributed event bus for **inter-module communication**. Since the distributed event bus works in-process by default (unless you configure a real distributed event bus provider). In that way, if you migrate to a microservice system later, these inter-module communication can become a inter-microservice communication without any code change (with just installing a distributed event bus provide package). If you are publishing an event and always handling it in the same module, you can use the local event bus for that event. +* If you are building a monolith (non-modular) application, you can always use the local event bus. + +The distributed event bus works in-process by default. Unless you don't configure a real distributed event bus provider, it works just like the local event bus. Once you configure a real distributed event bus provider, all your events become distributed. + +So, you use the local event bus only if you an event should always remain in-process in any scenario. For other type of events, use the distributed event bus. + +### Technical Differences + +There are some technical differences between the local and distributed event bus: + +* You can send entities or other non-serializable objects using the local event bus since these objects are not serialized/deserialized on event publishing. On the other hand, distributed event bus serializes/deserializes objects once you use a real distributed event bus provider. +* The local event bus is always transactional in the database level. For distributed event bus, you should enable inbox/outbox pattern to ensure data consistency once you use a real distributed event bus provider. + +These differences are because of the distributed event bus supports distributed scenarios while the local event bus is only used for in-process messaging. When you don't set up a real distributed event bus provider, these differences are not valid. \ No newline at end of file