Cheat sheetMS-02

Event-Driven Microservices

Microservices & APIs / Event-Driven Microservices

Services emit immutable events and react to them, replacing synchronous command chains with asynchronous flows, sagas, and eventual consistency.

01
Events as factsPublish 'something happened'. The emitter does not know consumers - the root of loose coupling.
02
Choreography vs orchestrationChoreography: no controller, flow emerges. Orchestration: a coordinator makes the flow explicit.
03
SagasMulti-service ops are local transactions plus compensating actions - not a global rollback.
04
Eventual consistencyViews briefly diverge then converge. Design UX and reads to expect it.

Prefer events for state propagation between services and reserve synchronous calls for queries where a fresh answer is required now. For any operation spanning services, model a saga with an explicit compensating action for every step, and instrument every flow with a correlation ID so you can trace it.

Choreographed sagaOrderPlaced -> StockReserved -> PaymentTaken -> Shipped; on PaymentFailed, Inventory compensates by releasing stock.
Replayable logA new analytics service joins and rebuilds its read model by replaying the retained event stream from the beginning.
Choose orchestration when the process is complex and must be visible in one place
Choose choreography when decoupling matters more than a central view
Version event schemas like APIs; add correlation IDs to every event
eventssagaschoreographyeventual-consistencykafkaasync
review in 6d