On this page
Commit changes together
Save related changes together with an atomic action.
Before you begin: Reservations and Atomic Actions.
Commit related changes together
Use atomic { ... } when related database operations must succeed together:
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.
The snippet illustrates the transaction sequence; provide the ownership/completion checks and product lookup for your application before using it. Keep the stock schema minimum at zero.
Inside the block, reads see earlier writes. If an operation throws or must fails, all changes in the block roll back. Returning { ok: false } alone is a normal return, not a rollback instruction. Database transactions enclosing an endpoint or payment event may roll back the block if the containing action fails later too.
Supported operations are post reads, users.exists, the existing post create/edit/increment/delete helpers, and reservation methods. Post writes retain their existing schema validation and author semantics. Put related writes inside the block rather than queueing post writes before it. At most 128 post writes are allowed per block. Nested atomic blocks are rejected.
HTTP requests, payment creation, wallet charges, and other external effects are not allowed inside an atomic block. Complete the database action first, then perform external work with its own retry protection. Atomic blocks and reservation methods are currently available in endpoint processes and payment events, not guards, permissions, or post/user hooks.
Atomicity prevents partial changes; dedupe prevents repeating a completed action. Use both when a caller may retry. Lock contention or database conflicts can fail an action; Frontbacked does not automatically rerun it.
Reservations do not automatically follow payment expiry or confirmation. Choose a reservation lifetime appropriate to your workflow, and explicitly consume the business capacity and release its hold when completing an authorized purchase or booking.
Wig-store example
The wig theme uses both APIs in create_cart_payment and create_product_payment. Both endpoints require an attemptId; reuse it for an unchanged request and use a new value when starting a new attempt. Each stock-controlled wig shares the resource key wig:<productId> across both checkout paths. The payment ID is the reservation key, and holds last until the latest available payment-method deadline.
Payment creation stays outside the explicit atomic block. The enclosing endpoint transaction saves the payment, holds, and dedupe response together. If a cart line cannot be reserved, no new payable payment or partial cart hold remains.
Confirmation atomically updates stock and lifetime sales, records sale snapshots, and releases the holds. Failed-payment events release holds without recording sales. Expired holds stop counting automatically. A delayed confirmation—or an older payment without holds—must acquire available capacity again; if another customer has reserved it, fulfillment stops for an order review instead of overselling. Payment settlement itself is not reversed by an FRL fulfillment error.
Inside atomic, posts.findOne with an exact where.id protects that post while you read and update it. Use this for calculations that depend on the current stored value. payment.cancel may also be combined with reservation releases in an atomic block.