Q48: How do you handle data consistency between microservices?
Avoid direct writes into another service's database. Each service owns its data and publishes domain events or exposes APIs. Consumers update local projections asynchronously, using versioning, deduplication, and reconciliation. For multi-step workflows, use sagas and explicit business states. Define invariants that must be immediately consistent and keep them within one transactional boundary where possible; not every cross-service workflow needs a distributed transaction.
Key Takeaways
- Give each service clear data ownership.
- Use events, idempotency, reconciliation, and sagas for cross-service workflows.