SD Core

Distributed Transaction

Coordinates writes across multiple services/stores — 2PC for strong consistency or sagas for eventual consistency.

Interview tip Lead with a 30-second definition, then one real system example and name 2–3 designs where Distributed Transaction is non-negotiable.

① What it is (30 seconds)

Coordinates writes across multiple services/stores — 2PC for strong consistency or sagas for eventual consistency.

② How it works in system design

2PC: prepare + commit coordinator — blocks on failure. Saga: sequence of local transactions with compensating actions (cancel shipment if payment fails). Outbox ensures reliable event publish.
Typical placement
ClientEdge / GatewayDistributedServicesData stores

③ Concrete system design example

Scenario: Ticket booking: reserve seat (DB lock) + charge card (PSP). Saga: if charge fails, release seat compensating transaction. Avoid global 2PC across PSP and DB.

④ Important interview Q&A

QuestionAnswer
2PC problems?Blocking, coordinator failure, not across heterogeneous systems well.
Saga orchestration?Central coordinator tracks steps; choreography uses events — pick based on visibility needs.
Exactly-once illusion?At-least-once + idempotent steps + dedupe keys = practical exactly-once business effect.

⑤ Seen in these system designs

In interviews, after explaining the concept, say: "This shows up directly in …" and link two designs.

⑥ Revision checklist

  • 2PC vs saga
  • Compensating actions
  • Idempotent steps
  • Outbox for events
saga2pctransactions