Problem
Fusetron Sound sells records that often exist as a single copy. A Shopify cart does not reserve stock, so two shoppers can have the last copy in their carts at once. Whoever pays first gets it, and the other shopper finds out at checkout. The owner asked for a short hold, so that a shopper who adds a rare record has time to finish buying it.
Solution
Before writing any code, I tested how Shopify tracks inventory on a development store. A Draft Order can reserve a unit until a set deadline. The unit moves from available to reserved, the store's stock counts stay true, and the normal checkout cannot sell that copy to anyone else. I built the hold on that feature instead of changing stock counts by hand.
The owner tags a product on-hold to turn the hold on for it. Ordinary products keep Shopify's normal cart, untouched. A held record appears in the cart drawer as its own line, with a countdown and a link to release it. At checkout, the held records and the ordinary cart lines go onto one Draft Order, so the shopper pays once.
How It Works
- A theme app extension loads the storefront script. On a tagged product, the script asks whether the copy is free, and the button reads Sold out while another shopper holds it.
- When the shopper adds a tagged record, the request goes to the store's own domain. Shopify's App Proxy signs it and forwards it to a Cloudflare Worker.
- The Worker checks the signature, records the hold in Cloudflare D1, and adds the record to that shopper's Draft Order with a 10-minute deadline.
- At checkout, the Worker adds the shopper's ordinary cart lines to the same Draft Order and sends the shopper to pay.
- A scheduled job runs every 5 minutes and releases holds that ran out.
- The app's page in the Shopify admin lists the records held right now and the latest 200 reservation events, in plain English.
Hard Cases
Two Shoppers, One Copy
Shopify will reserve the same copy on two Draft Orders without complaint. When two shoppers add the last copy at the same moment, the Worker now lets exactly one succeed and tells the other to try again.
One Shopper, Two Requests
A shopper's holds share one Draft Order, and Shopify replaces all of its lines on every update. Two requests at once could overwrite each other. A per-shopper lock in D1 makes them take turns.
Requests That Get Cut Off
If a request fails after Shopify creates the Draft Order, the Worker finds the orphaned order by its tag and deletes it. A hold stuck halfway is given up after one minute, so the shopper can try again.
Paying At The Deadline
A shopper who starts paying before the deadline gets 10 more minutes. Shopify keeps the copy reserved past that, so the Worker always cleans up before the copy can go to someone else.
Security
Every way into the Worker is checked. Storefront requests, launches from the Shopify admin, and Shopify webhooks each carry a Shopify signature. The Worker verifies it with the app secret, rejects anything older than 5 minutes, and compares signatures in constant time. A request that skips the App Proxy gets a 401, which I confirmed against the live Worker on November 30, 2026. A shopper can read and change only their own holds. No Shopify credential lives in the browser or the repository. The Worker gets a short-lived Admin API token when it needs one.
Release And Validation
Each version is a Git tag tied to exactly one deployment. I cut versions 1.0.0 through 1.4.0 between November 22 and November 25, 2026, and the changelog records what changed for shoppers and the known limits of each one. On November 30, 2026, the 83 Worker tests and 8 storefront tests passed and the typecheck was clean. A Playwright verification skill drives the live store through reserve and release, a mixed-cart checkout that stops before payment, last-copy races, and recovery from cut-off requests. The code is open source under the MIT license, with a guide for running it on another store.