Course contentsShow
← Software Engineering
Lesson 1285 of 1,93338. Layered and Modular ArchitectureFree lesson

Domain Events for Context Integration

Using domain events to communicate changes across bounded contexts while maintaining loose coupling.

Domain Events for Context Integration

You'll learn how to use domain events to safely share information between bounded contexts without creating tight coupling.

What Are Domain Events?

A domain event is a record of something meaningful that happened in your system — like "Order Placed," "Payment Completed," or "Inventory Reserved." When one bounded context needs to know about changes in another, domain events provide a clean way to communicate without direct dependencies.

Think of domain events like a company newsletter: when the sales department closes a deal, they publish an announcement. The shipping department reads it and prepares inventory. The accounting department reads it and generates an invoice. Sales doesn't need to know who's listening or what they'll do with the information.

How They Enable Loose Coupling

Instead of Context A directly calling Context B's API (tight coupling), Context A publishes an event: "Something happened." Context B subscribes to events it cares about and reacts accordingly. Neither context needs to know the implementation details of the other — they only share the event contract.

For example:

  • Order Context publishes OrderPlaced event
  • Inventory Context subscribes, decrements stock
  • Notification Context subscribes, sends confirmation email
  • Analytics Context subscribes, updates reports

Each context remains independent. You can add new subscribers without modifying the publisher. You can change internal implementations without breaking the integration.

Event Structure

Domain events typically contain:

  • Event name (what happened)
  • Timestamp (when it happened)
  • Relevant data (minimal info needed, like order ID and items)
  • Context identifier (which aggregate changed)

Events are immutable facts about the past, named in past tense.

Key Takeaway: Domain events let bounded contexts react to changes in other contexts through publish-subscribe patterns, maintaining autonomy while enabling necessary coordination across your system's boundaries.