Event sourcing

Store state as an immutable log of events rather than current values. The current state is derived by replaying events. Benefits: complete audit trail, temporal queries, and rebuilding projections from scratch.

CQRS — Command Query Responsibility Segregation

Separate the write model (commands that mutate state) from the read model (optimised query views). The write side emits events; projections consume events and maintain read-optimised views.

Outbox pattern

Solves the dual-write problem: writing to a DB and publishing an event atomically. Instead of writing to both, write only to the DB — including an outbox table in the same transaction. A separate process reads the outbox and publishes events to Kafka. If the publish fails, the outbox row is retried.

When event-driven makes sense

  • Multiple systems need to react to the same business event.
  • Decoupling producer from consumer release cycles.
  • Audit and replay requirements.