Most side projects die on the same rock: the work is slow, the payment is instant, and the browser has no idea what to do in between.

I hit this while shipping a made-to-order audio product. A buyer types a short brief, pays, and expects to hear something within a couple of minutes. Audio rendering is not an API call you can hide behind a spinner for 3 seconds. It is a queue, a worker, a file, and a notification — four places where a retry can duplicate work or lose it entirely.

Here is the design that survived contact with real payments, written down because the constraints generalise to any slow job behind a checkout button.

The failure mode nobody plans for

The happy path is easy: order comes in, job enqueues, worker renders, file lands in storage, email goes out. The interesting path is when the payment provider retries its webhook because your endpoint took 12 seconds, and now you have two orders, two jobs, and one very confused customer.

Stripe (and every other provider) will retry. If your handler is not idempotent, retries are duplicates, and duplicates are money-shaped bugs.

Three keys, in order

  1. Idempotency key from the provider. Store the webhook event id with a unique constraint, and insert-then-ignore duplicates. Do this before any side effect, not after.
  2. Deterministic job id. Derive the queue job id from the order id, not from a random uuid. Two enqueues of the same order collapse into one job.
  3. Idempotent render. The worker writes to a path derived from the job id and treats "file already exists and is newer than the brief" as done. A retried worker becomes a no-op instead of a second charge on your render budget.
def handle_webhook(event): with transaction(): if not events.insert_if_absent(event["id"]): return 200, "duplicate" order = orders.mark_paid(event["data"]["object"]["id"]) if order: queue.enqueue("render", job_id=f"render-{order.id}", args=[order.id]) return 200, "queued" 

That is the whole trick. Everything else is scheduling.

Previews beat promises

The product decision that mattered more than any of the above: show the buyer something before the final job runs.

We generate short preview clips from the same brief the full track uses, and the buyer approves or revises before the paid render is committed. Two effects:

  • Support load drops. The "this is not what I expected" emails move before payment instead of after.
  • The expensive job only runs once, on content the buyer already accepted.

If you are building anything generative with a human on the other end, the preview is not a nice-to-have. It is the cheapest quality control you will ever ship.

What I would not do again

  • Polling. I started with the browser polling every two seconds. It works, but it burns requests and it makes the UI feel broken on slow connections. A webhook plus a small "ready" state is calmer.
  • Storing the brief as free text only. The structured fields (occasion, names, tone, things to avoid) are what let the worker validate input and what let support answer questions six weeks later.
  • One queue for previews and finals. Previews are cheap and must be fast; finals are expensive and must be correct. Different queues, different concurrency, different retry policy.

Numbers, since they are the only honest part

A 90-second clip renders in roughly 40 to 70 seconds on a single worker. The queue absorbs bursts of about 20 orders without visible delay, which is far more headroom than a small store needs. The parts that broke were never the render — they were the webhook retries and one worker that silently died mid-job and left an order stuck in rendering.

Fix for the stuck order: a sweeper that re-enqueues jobs older than 15 minutes with no artefact. Ten lines, catches everything.

The product this came from is Dearlume Gifts, a made-to-order personalised song store. The architecture notes above are the parts I would keep if I rebuilt it tomorrow.