How do you handle data consistency across microservices with separate databases?

Data consistency across microservices with separate databases is achieved by replacing cross-service transactions with either the Saga pattern or an event-driven, eventually-consistent approach, since a single ACID transaction can't span multiple databases.

Key Points

Example

When a customer updates their shipping address, the Customer service publishes an AddressUpdated event; the Order service and Shipping service consume that event asynchronously and update their own cached copies of the address, rather than the Order service querying the Customer database directly.

// Outbox relay: publishes saved events to Kafka, then marks them as sent.
// The business change and the outbox row were written in one transaction.
@Component
public class OutboxRelay {

    @Scheduled(fixedDelay = 1000)
    @Transactional
    public void publish() {
        for (OutboxEvent e : outbox.findTop100BySentFalseOrderByIdAsc()) {
            kafka.send(e.topic(), e.aggregateId(), e.payload());
            e.markSent();
        }
    }
}

// Consumers must be idempotent: a crash after sending but before markSent()
// means the same event can be published twice.

Interview Tip

A concise interview answer is

Since each service owns its own database, I rely on the Saga pattern for multi-step business transactions and event-driven updates for keeping local copies of data in sync, accepting eventual consistency instead of a distributed transaction. Reliable delivery patterns like the outbox pattern and idempotent consumers keep that eventual consistency correct.

Last updated: 1 November 2026

Previous question: What are the challenges of managing multiple databases in a microservices architecture?

Next question: What strategies can be used for data replication or synchronization between microservices?

More Microservices Design Patterns interview questions

All Microservices Design Patterns questions