drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

Locks

drift.Backbone.Lock: distributed locks, so work is not done twice.

Signatures

Go
// Acquire mints a FRESH token every call; Release takes it back
Acquire(name string, ttlSeconds int) (string, error)   ·   Release(name, token string) error
Go
token, err := drift.Backbone.Lock.Acquire("payout:42", 30)   // hold for up to 30s
if err == nil {
    defer drift.Backbone.Lock.Release("payout:42", token)
    // ... do the work exactly once ...
}

Size the TTL for the whole job

There is no renew from Acquire.

Calling it again to stay alive mints a fresh token each time, which presents as a different holder and is refused while your own lock is still live. Pick a TTL that covers the whole job.

Go alone can hold a lock open

Go
// AcquireAs and Renew: Go only, so far
AcquireAs(name, owner string, ttlSeconds int) (string, error)   // renews if OWNER already holds it, takes it if free
Renew(name, token string, ttlSeconds int) error                 // extends a lock you already hold, by TOKEN

AcquireAs takes a stable owner you choose instead of a minted one, so calling it again under the same owner while your lock is still live extends the TTL instead of being refused: one call that means "renew if it's mine, take it if it's free or expired, refuse if someone else holds it." Renew extends a lock you already hold without releasing it first, and fails if the lock is gone, already expired, or owned by someone else, in which case treat that as "I am no longer the holder" rather than retrying into a second active one.

Neither exists yet in Python, Node.js, Ruby, PHP or Rust: size the TTL for the whole job there, as the WARNING above says. The CLI's own drift backbone lock renew names an owner explicitly the same way AcquireAs does, which is what lets it renew from outside a function regardless of which language deployed it.

A lock held by someone else answers 409, so the second worker backs off. Past your tier's concurrent-lock limit, Acquire answers 429. A TTL of zero or less becomes 30 seconds. Lock names are not charset-restricted, so payout:42 is fine.

Locks are not captured in a snapshot, so restoring one gives you no held locks, which is the correct outcome for a primitive whose whole meaning is "right now".