← Microservices learning path
Microservices · Module 5 of 10

Data management in microservices

Handle data and consistency across services.

📖 Key ideas

  1. Database per service keeps autonomy.
  2. Distributed transactions are hard; avoid two-phase commit.
  3. Sagas coordinate multi-step business transactions with compensating actions.
  4. Eventual consistency is normal across services.
  5. 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