Finding · affects your reliability

Background jobs that run inside requests

Work fired off from a request handler without a queue dies on deploys and crashes, never retries, and competes with live requests for the same server.

Why it matters

Sending an email, recording a click or generating a summary "in the background" from inside a handler feels free. But that work lives in the same process as the request: a deploy or a crash drops it, a failure isn't retried, and it uses the CPU your live requests need.

At small scale you rarely notice. At scale, "rarely" becomes a steady trickle of lost emails and missing records, with nothing in the logs to say which.

What it looks like

Fire-and-forget work started inside a request:

Before
export async function POST(req: Request) {
  const order = await createOrder(req);
  sendReceiptEmail(order).catch(() => {}); // lost on deploy, never retried
  return Response.json(order);
}

How to fix it

After
export async function POST(req: Request) {
  const order = await createOrder(req);
  await queue.send({ type: "receipt", orderId: order.id }); // durable
  return Response.json(order);
}
// a worker consumes the queue, with retries and a dead-letter queue
  1. Publish the job to a durable queue (SQS, a managed queue service, or your platform's background functions) instead of running it inline.
  2. Process it in a worker with retries and a dead-letter queue.
  3. Low-stakes work (a cache refresh, a title) can wait until a queue exists for other reasons.

A real example: Dub

Computed by Skeram’s engine from the published teardown of Dub, at 10,000 monthly users (critical):

8 background jobs run inline in request handlers. Cache warm + partner enrollment lookup via waitUntil in link redirect handler; Send password-reset confirmation email post-response; Increment workspace aiUsage counter post-response (+5 more). Work fired from a handler without a queue dies with the process on deploys and crashes, fails silently with no retry, and competes with requests for the same instance.

Suggested fix: Move to a queue (SQS + a worker service, as in the architecture shown, sized for this load). The handler has to be rewritten to publish to it instead of firing inline.

Evidence: lib/middleware/link.ts:95-120, app/api/auth/reset-password/route.ts, app/api/ai/completion/route.ts.

How Skeram detects it

The extraction records each background job and how it's triggered. Jobs triggered inline from a handler are flagged, graded by what losing one costs: a lost email or payment record is serious, a lost cache refresh isn't.

When it starts to hurt: A warning from about 1,000 monthly users, critical from about 10,000, when lost work stops being rare.

Every finding cites the file and line it came from, and scanning again after a fix shows it resolved in History. How the analysis works.

Questions

Does a queue cost more?

Very little. SQS costs cents at small scale. Skeram adds the queue and a small worker to the forecast so you can see the real difference.

Related findings

Find it in your code

Skeram reads your repo, prices every model call from 100 to 100,000 users, and flags these patterns with the file and line.