Skip to content

Domain Event

Spicy — senior dev territoryBackend

ELI5 — The Vibe Check

A domain event is something meaningful that happened in your business. Not 'row updated in users table' but 'UserRegistered' or 'OrderShipped.' It speaks the language of the business, not the database. Other parts of the system react to these events to do their thing.

Real Talk

A domain event is a record of something significant that occurred in the domain model, expressed in ubiquitous language. It captures a state change with its context (who, what, when, why) and is typically immutable. Domain events enable loose coupling between aggregates, bounded contexts, and services in domain-driven design architectures.

Show Me The Code

class OrderShipped {
  constructor(
    public readonly orderId: string,
    public readonly trackingNumber: string,
    public readonly shippedAt: Date,
    public readonly carrier: string
  ) {}
}

eventBus.publish(new OrderShipped(order.id, 'UPS123', new Date(), 'UPS'));

When You'll Hear This

"When an order ships, we publish an OrderShipped domain event that triggers email and inventory updates." / "Domain events should describe what happened, not what to do — 'OrderPlaced' not 'SendConfirmationEmail'."

Made with passive-aggressive love by manoga.digital. Powered by Claude.