EDA Overview

EDA Overview

Event-Driven Architecture (EDA) uses events as the primary communication mechanism between components. A publisher emits a fact; subscribers react. The publisher doesn't know who's listening.

At the architecture level, EDA is the Open-Closed Principle: adding a new reaction means adding a new subscriber, not modifying the publisher.

The shape

[Publisher A] -- emits --> [Event Bus] -- delivers --> [Subscriber 1]
                                       ----------> [Subscriber 2]
                                       ----------> [Subscriber 3 (added later)]

Three claims worth checking:

  1. The publisher doesn't know who subscribes.
  2. Subscribers can be added/removed without touching the publisher.
  3. The bus is the only coupling between publisher and subscribers.

The concept notes

When EDA pays off

When EDA is overkill

What EDA is not

Two failure modes

  1. Hidden coupling. Subscribers depend on the publisher's internal state via event payload. Renaming a field breaks them. Treat the event as a published contract — version it.
  2. Causal soup. Many events flying around, no clear flow. Hard to debug, hard to test. Trace events; document key flows; consider orchestration.

A minimal example

@dataclass(frozen=True, kw_only=True)
class ItemAddedToCart:
    cart_id: UUID
    item_name: str
    quantity: int

class EventBus:
    def __init__(self):
        self._subs: dict[type, list[Callable]] = {}
    def subscribe(self, event_type, handler):
        self._subs.setdefault(event_type, []).append(handler)
    def publish(self, event):
        for handler in self._subs.get(type(event), []):
            handler(event)

# Producer
bus.publish(ItemAddedToCart(cart_id=..., item_name="book", quantity=1))

# Consumer (added later, publisher unchanged)
def update_inventory(e: ItemAddedToCart): ...
bus.subscribe(ItemAddedToCart, update_inventory)

That's the whole pattern. Everything else is choosing where the bus runs (in-process vs broker), when subscribers fire (sync vs async), and what guarantees the bus provides.