Entity Framework Core Interview Question #122
How do transactions interact with external services such as payment APIs?
Change Tracking, Updates, Transactions & Concurrency Mid-Level Intermediate
Quick Interview Answer
A database transaction cannot normally make an external HTTP service participate in the same atomic local transaction. Holding a database transaction open while waiting for an external API also increases lock duration and failure complexity.
Detailed Explanation
A database transaction cannot normally make an external HTTP service participate in the same atomic local transaction. Holding a database transaction open while waiting for an external API also increases lock duration and failure complexity.
For workflows spanning a database and external systems, designs such as idempotency, durable messages, the outbox pattern, compensating actions, and state machines are often more appropriate.
The architecture should explicitly handle the possibility that one side succeeds while another side temporarily fails.
Code Example
// Typical approach:
// 1. Save business state + outbox message in one DB transaction.
// 2. Commit.
// 3. Background processor sends external message.
// 4. Mark outbox record as processed.
// 5. Make external operation idempotent.