You give up a single distributed transaction and use a saga: a sequence of local transactions where each step publishes an event that triggers the next, and every step has a compensating action to undo it. Consistency becomes eventual, so the design work is deciding what to compensate, what to retry and what to escalate to a human. Model the flow explicitly, either choreographed through events or coordinated by an orchestrator.
Why interviewers ask this
The interviewer is testing whether you reach for two phase commit or understand why almost nobody runs it across services. They want to hear about compensating actions, idempotency, the semantic difference between rollback and refund, and how you keep the state machine visible. It also probes whether you would question the service boundaries in the first place, since some of these steps may belong together.
How to structure your answer
- Explain why a distributed transaction is not the answer.
- Define the saga: local transactions plus compensations.
- Contrast choreography with orchestration and pick one.
- Cover the messy parts: partial failure, retries, human escalation.
Example answer
A two phase commit across three services and three databases means holding locks across the network and a coordinator that can block everything if it dies, so I would not do it. Instead the flow becomes a saga. Each service does its own local transaction and emits an event, and each step has a defined compensation: if shipping cannot allocate, we release the inventory reservation and refund or void the payment. The important thing is that compensation is a business action, not a rollback; a refund leaves a visible record and that is correct. For anything with more than about three steps I use an orchestrator rather than pure choreography, because with choreography the actual flow lives nowhere and no one can answer where an order is stuck. An orchestrator gives me one state machine, timeouts per step and a queryable status. Every step is idempotent and retried with backoff, and anything that exhausts retries lands in an operations queue with the order id, because some failures genuinely need a person.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What do you do when the compensating action itself fails?
- How would you show a customer the state of an in flight order?
- When would you merge two services rather than run a saga between them?
Related backend developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions