The Problem: Distributed Partial Failures
In microservices architectures, business workflows (such as payment processing, order placement, and inventory reserving) span multiple independent databases. Distributed 2PC (Two-Phase Commit) protocols introduce severe latency and single-point-of-failure bottlenecks.
To achieve ACID semantics across autonomous services without distributed locks, production architectures combine:
Idempotency Keys : Guaranteeing duplicate HTTP requests (e.g. from network retries) execute exactly once.
The Saga Pattern : Executing sequential local transactions coupled with compensating transactions on failure.
System Workflow
Client Request (ID: uuid) | v +---------------------+ Acquire Lock & Check Cache +--------------------+ | Idempotency Filter | ------------------------------------> | Redis Key Store | | (FastAPI Middleware)| <------------------------------------ | (TTL, State: PEND) | +---------------------+ Cache HIT -> Return Replay +--------------------+ | Cache MISS v…