Microservices can't do 2PC across services. Saga pattern: series of local transactions with compensations. Complex but works at scale.
Local transactions
Each service commits locally. No distributed lock. Success = next step. Failure = trigger compensation.
Local transactions
Each service commits locally. No distributed lock. Success = next step. Failure = trigger compensation.
Compensating actions
For each forward step, define undo. Refund charged payment. Release reserved inventory. Not always semantically identical to rollback.
Orchestrated saga
Central orchestrator commands each step. Explicit. Easier to reason about + monitor. Downside: orchestrator is a service.
Choreographed saga
Services publish events. Others react. No central controller. Decentralized. Harder to trace.
Idempotent compensations
Compensations may retry. Must be safe to run twice. Design in from day one.