What are the core patterns of Event-Driven Architecture (EDA)?

Topic: microservices, Architecture. Level: Intermediate.

Answer

- **Event Notification**: a thin event says "something happened" (`OrderPlaced{id}`); consumers call back for details. Low coupling, more chatter. - **Event-Carried State Transfer**: the event carries all needed data, so consumers keep local read models and avoid callbacks. - **Event Sourcing**: the event log *is* the source of truth; state is rebuilt by replaying events. - **CQRS**: separate write and read models, often fed by events. Events should be immutable, named in past tense, versioned, and self-describing. ```java // Event notification (thin) record OrderPlaced(String orderId) {} // Event-carried state transfer (fat — consumer needs no callback) record OrderPlaced(String orderId, String customerId, List<LineItem> items, long totalCents, Instant placedAt) {} ```