Pick the fix
An order service must update its own Postgres and a separate inventory service's Postgres atomically. What do you recommend?
Hint 1 of 1
Which option avoids holding locks across services?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A saga: reserve inventory, create the order, compensate on failure, driven by events with an outbox
Correct. Each step is local and committed; failures run compensations instead of holding locks.
When two services own two databases, an atomic commit across both means blocking and tight coupling. A saga makes each step a local commit and undoes earlier steps if a later one fails.
Why not the others?
- B XA two-phase commit across both databases. Couples the services and blocks if the coordinator fails.
- C Write to both databases and hope. A crash between the writes leaves them inconsistent.
- D Put both tables in one database owned by the order service. Breaks the inventory service's ownership of its data.