Hard java spring

A business transaction spans multiple databases. How do you keep it consistent?

The 30 second answer

I avoid distributed two-phase commit across services and use a saga instead. It is a chain of local transactions, coordinated by events or by an orchestrator, and if a step fails, compensating transactions undo the earlier steps. The cost is that there is no isolation, so others can see in-between states. I handle that with explicit statuses like pending and with idempotent steps.

Avoid distributed 2PC across services. Use a saga: a chain of local transactions where each step publishes an event or is called by an orchestrator, and a failed step triggers compensating transactions that undo earlier steps. The cost is that there is no isolation, so other readers can see in-between states; I handle that with status fields such as PENDING and with idempotent steps. Follow-up: Orchestration or choreography? (Orchestration when the flow has many steps and needs one place to see the state.)

Sources (1)
  1. microservices.io: Saga