Distributed Locking
To prevent race conditions, duplicate operations, and data inconsistency under high concurrency, the Partner API implements an advanced multi-key distributed locking algorithm. This system ensures that only one significant operation can be performed for a single user at any given time.
Mechanisms
The locking system uses a hybrid approach leveraging both PostgreSQL and Redis to enforce strict atomic serialization. When any process affecting a user's state or asset balance is initiated, the system attempts to acquire a dist lock.
Protected Operations
The following endpoints are protected by this locking mechanism to guarantee atomicity:
- Registration: User Register
- Transactions:
Wait-Timeout Errors: If you receive a 409 Conflict (Wait-Timeout Error), it indicates that the user is currently locked by another concurrent process. This mechanism effectively eliminates duplicate resource allocation and prevents race conditions in your integration.
Implementation Benefits
This robust system eliminates data visibility bugs and phantom-reads across distributed environments. By serializing transactions globally per user, Treasury guarantees near-zero failure rates for ledger operations and ensures perpetual consistency between partner-side and Treasury-side records.