Back to work

Live Shopify app, open source

Shopify Cart Hold

A Shopify app that reserves a rare record for 10 minutes once a shopper adds it to the cart, so nobody else can buy that copy while they finish. I built it at the request of Fusetron Sound, a record store, and it runs on their storefront.

Product Surface

Cart drawer on the live store with a held CD reserved for 10 minutes, below an ordinary LP
The live store's cart drawer. The held CD has its own line, a timer, and a link to release it. The LP above it is an ordinary cart line.
Cart page on the live store with the held CD showing 9 minutes 52 seconds left
The same reservation on the cart page, counting down. Both screenshots come from a verification run on the live store on November 22, 2026.

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

  1. 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.
  2. 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.
  3. 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.
  4. At checkout, the Worker adds the shopper's ordinary cart lines to the same Draft Order and sends the shopper to pay.
  5. A scheduled job runs every 5 minutes and releases holds that ran out.
  6. 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.