← Microservices learning pathMicroservices · Module 5 of 10
Data management in microservices
Handle data and consistency across services.
📖 Key ideas
- Database per service keeps autonomy.
- Distributed transactions are hard; avoid two-phase commit.
- Sagas coordinate multi-step business transactions with compensating actions.
- Eventual consistency is normal across services.
- CQRS and event sourcing are advanced patterns.
💡 Real-life example: A saga is a travel booking: book flight, hotel, cab; if the cab fails, cancel the hotel and flight.
SagaSequence of local transactions with compensations
Compensating actionUndo step on failure
Eventual consistencyData becomes consistent over time
Event sourcingStoring state as a sequence of events