Section 066
Single-Writer Lease
Exactly one executor instance may open positions at a time, enforced by a database lease renewed every 15 seconds.
Deployments, restarts and failovers can briefly leave two executor processes running. Two writers would send duplicate entries. The executor prevents this with a single-writer lease stored in the database.
How the lease works:
- An instance acquires the lease row with its identity and an epoch number. The epoch increases with every new holder.
- The holder renews the lease every 15 seconds.
- If renewals stop, the lease expires 120 seconds after the last renewal, and another instance may take it with a higher epoch.
- Every entry order checks that its instance holds a valid lease with the current epoch immediately before sending. An instance that lost the lease cannot open anything, even if it is still running.
- Reduce-only orders do not require the lease. During a handover, any instance may still reduce risk, and reduce-only semantics guarantee that duplicates can only shrink positions, never grow them.
A local process lock adds a second guard on the same host. Together they make deployments safe without pausing the product: the new instance waits for the lease, reconciles with the venue, and resumes entries from where the old one stopped.