Module 93: Domain-Driven Design

Lesson 5 of 5 · 15–25 minutes

Domain events

🏠The everyday picture

When a train leaves a station, an announcement goes out. The next station prepares, the catering team restocks, and the display boards update. The driver doesn't phone each of them; they react to the announcement.

📘What it really is

🖱️Try it

Add domain events to the booking platform: SessionBooked, PaymentReceived, SessionConfirmed, SessionCancelled. Implement an outbox table written in the same transaction as the aggregate, and a worker that reads it every few seconds and calls handlers (confirm booking on payment, send confirmation email, schedule a reminder). Make the email handler idempotent, and test by delivering the same event twice.

✅Quick check

How are domain events named?

Show the answer

In the past tense, in the business's language, describing something that happened (for example, SessionBooked).

What problem does the outbox pattern solve?

Show the answer

It ensures a change and its event are saved together, so events are never lost or published for changes that didn't happen.

← PreviousAggregates
ProLearners Assist