OpenHedgeDocs
Menu

Part VI · Unified Executor

Section 066

Single-Writer Lease

Exactly one executor instance may open positions at a time, enforced by a database lease renewed every 15 seconds.

T+0Lease acquiredEpoch nevery 15 sRenewedEntries allowedrenewals stopOld holder downReduce-only still allowed+120 sLease expireshandoverNew holderEpoch n+1, reconcile first
Figure 66Lease renewal, expiry and handover.

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.

© 2026 HedgeFund DAO · OpenHedgeNot investment advice. Trading leveraged perpetuals can lose all deposited funds.