DocsPayments & workflows
On this page

Reservations and Atomic Actions

Hold stock, appointment capacity, equipment, or seats while someone completes a workflow. Reservations use your own resource and attempt keys; they are independent of products, users, and payments.

Hold capacity

Use reservations in endpoint processes and payment events:

backend/index.frl
Rule input (JSON)

Use a complete version 2 rule file. Select a post with “postType” and “action”, or an “endpoint” by name. Saved data, jobs, payments and email need the local server. Dedupe replay protection also needs a site.

Check complete rules or run schemas, permissions, hooks and calculations against the input above. Add excerpts to a complete rule before running.

reservation.hold(resourceKey, reservationKey, options) accepts:

Argument or optionMeaning
resourceKeyYour capacity pool identifier, such as product:abc or workshop:morning.
reservationKeyA stable identifier for this hold. Reuse it when retrying.
capacityA non-negative integer or a source reference.
quantityA positive integer; defaults to 1.
expiresInLifetime in seconds, from 1 to 604800 (seven days). Use this or expiresOn.

Alternatively, pass expiresOn as a future ISO timestamp within seven days. This lets a hold match an existing booking or payment deadline exactly. Do not combine it with expiresIn.

Keys must be nonempty strings of at most 200 characters and are scoped to the site. No user ID is added automatically. Endpoint guards control who may reserve or release capacity: possession of a reservation key is not authentication. Use one resource key consistently for each pool; giving the same stock field several different resource keys creates independent pools.

Success returns:

json

An active matching hold returns the original reservation with replayed: true. It does not extend the deadline. Replays need not include available; use the reservation details to resume the workflow.

Unsuccessful resultMeaning
insufficient_capacityNot enough unreserved capacity. Includes available.
conflictThis reservation key already identifies a different quantity.
source_conflictThis resource key was registered with a different capacity source.
terminalThis hold has expired or been released. Use a new reservation key for a new attempt.

These return { ok: false, reason: "..." }. Invalid options or inaccessible sources throw an error. Use must(result.ok, message, status) when an unsuccessful hold should fail the endpoint or roll back an atomic block.

Reference current capacity

Instead of passing a previously read number, point to the field that owns capacity:

frl

Rule excerpt: add this to a complete FRL rule before running it. Try a complete example →

The IDs identify records, not data objects. Object paths can be nested; array positions and unsafe property names are rejected. The source must exist and contain a non-negative integer. Post references require read access to the post and an accessible field. User-data references currently support the authenticated user's own data and exclude backend-only fields.

Frontbacked reads the source while protecting the reservation check from concurrent updates. The same resource key must keep the same source. A numeric capacity remains supported: each hold uses the number supplied for that call, but Frontbacked cannot detect whether your number was calculated from stale data. Do not accept capacity directly from an untrusted request.

Capacity is the amount available before subtracting active holds. Reducing capacity below existing holds prevents new holds; it does not cancel existing reservations. Expired holds automatically stop counting against capacity. No expiry cleanup call is necessary.

Read and release

frl

Rule excerpt: add this to a complete FRL rule before running it. Try a complete example →

get returns the reservation or null. Its status is held, expired, or released; active reflects its current deadline. Inside an atomic block, reading the hold also protects it from concurrent release while that block completes.

release returns { ok: true, released, reservation } for an existing hold. Releasing an already released hold or a missing key succeeds harmlessly; a missing key is a no-op. Expired and released holds cannot be revived by hold.

Limit active holds and repeated expirations

reservation.stats(resourceKey, { window: 900 }) returns activeCount, activeQuantity, and expiredCount. Active totals include all currently held reservations. expiredCount counts unreleased holds that expired within the last window seconds (1–604800; default 900). Releasing a hold removes it from these statistics.

For customer limits, use a separate capacity pool such as customer-checkouts:${$actor.id}. Hold one unit in that pool together with your stock holds inside the same atomic block. Its capacity controls how many simultaneous checkouts that customer can reserve. Use another pool for a total-unit limit if needed. Keep deadlines aligned with your workflow; retrying an active hold does not extend its deadline.

For a cooldown, check recent expirations before making a new hold. Keep expired quota holds unreleased until they leave the reporting window; release the quota immediately when the customer completes or cancels before expiry. Authenticate the customer and derive their resource key yourself.

Continue with Commit changes together.