Semantic Locks and Concurrent Sagas
Handle concurrency in sagas using countermeasures like semantic locks, commutative updates, and pessimistic views to prevent dirty reads and lost updates across overlapping transactions.
The Concurrency Problem
Sagas relax isolation: intermediate states are visible to other transactions. When two sagas touch the same data concurrently, you risk dirty reads, lost updates, and fuzzy reads.
This lesson covers countermeasures that restore safety without full ACID isolation.
Anomaly: Lost Update
A lost update happens when one saga overwrites a change made by another that it did not see.
- Saga A reads balance 100.
- Saga B reads balance 100, subtracts 30, writes 70.
- Saga A subtracts 50 from its stale 100, writes 50.
B's deduction is lost.
All lessons in this course
- Ensuring Idempotency in Sagas
- Retry Strategies for Sagas
- Advanced Compensation Logic
- Semantic Locks and Concurrent Sagas