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:
- The publisher doesn't know who subscribes.
- Subscribers can be added/removed without touching the publisher.
- The bus is the only coupling between publisher and subscribers.
The concept notes
- Domain Event vs Integration Event — internal vs cross-context, sync vs async.
- Event Bus / Publisher-Subscriber — the mechanism.
- Sync vs Async Event Handling — when each is right.
- Eventual Consistency — what you give up, what you gain.
- Choreography vs Orchestration — distributed workflow patterns.
When EDA pays off
- Many reactions to one event (notify, log, update read model, send email, …). Each as its own subscriber.
- Cross-team independence. Team A publishes
OrderPlaced, Team B builds whatever they need around it. - Decoupled scaling. Heavy subscribers run on their own infrastructure.
- Future-proofing. "What if someone wants to react to X later?" -> fine, they subscribe.
When EDA is overkill
- One publisher, one subscriber, one process. A direct call is simpler.
- Tight transactional consistency required across multiple effects.
- Small codebase. EDA's plumbing exceeds its benefit.
What EDA is not
- Not message queues. Queues are a transport. EDA is a pattern. You can do EDA in-process with no queue at all.
- Not Event Sourcing. ES stores events as the source of truth for state. EDA uses events for communication. You can do either alone.
- Not the same as CQRS. CQRS splits reads from writes; often paired with EDA, but neither requires the other.
Two failure modes
- 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.
- 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.