← Back to list challenge
Stock Movement Integrity - Race-Safe & Audit Chain
lockForUpdate + immutable movement_logs + delta-based recompute for stock consistency.
Problem
Concurrent Stock OUT could turn current_stock negative; corrections removed audit trail.
Decision
DB transaction + lockForUpdate, separate immutable movement_logs from mutable stock_movements.
Result
Race-safe stock IN/OUT, audit chain intact across corrections and soft-deletes.
Implementation
- Stock OUT race condition resolved via row-level lock inside a DB transaction.
- Audit chain movement_logs separated from mutable data - never erase trail.