Skip to content
RED SAGSkills
hardBackend Developer interview question

In a microservices system, placing an order touches the Order, Payment and Inventory services, each with its own database. How do you keep data consistent?

What the interviewer wants to hear

  • Avoid two-phase commit across services; explain why
  • Saga: sequence of local transactions with compensating actions
  • Choreography vs orchestration trade-offs
  • Reliable events via outbox; idempotent steps
  • Eventual consistency, intermediate states shown to users, timeouts

Model answer

There is no single ACID transaction across three databases, and two-phase commit is slow, couples services and blocks when the coordinator fails, so I would use a saga. A saga is a series of local transactions, each with a compensating action. For example: Order service creates the order as PENDING, Inventory reserves stock, Payment charges the card, then the order becomes CONFIRMED. If payment fails, Inventory releases the reservation and the order becomes CANCELLED. With choreography, services react to each other events, which is simple for few steps but hard to follow. With orchestration, a central orchestrator, for example using Temporal or a state machine, tells each service what to do, which is easier to monitor. Each step publishes events via an outbox and must be idempotent. The system is eventually consistent, so the UI shows states like pending, and timeouts trigger compensation.

Can you answer it under time pressure?

Take a timed hard round and get scored on every answer.

Start mock interview

More hard Backend Developer questions