background-jobs
Installation
SKILL.md
Background Jobs
Overview
Anything slow, flaky, or scheduled belongs off the request path: sending email, processing uploads, calling third-party APIs, nightly rollups. Use a job system — Inngest or Trigger.dev (serverless-friendly), or BullMQ + Redis (self-hosted) — that gives you retries, backoff, and observability. The request just enqueues and returns; the worker does the work with idempotency so retries are safe.
When to use
- A task takes more than ~1s or calls an external API that can fail.
- Scheduled/recurring work (digests, cleanup, syncing).
- Fan-out work (notify every member of an org).
The pattern (Inngest-style)
// src/server/jobs/send-invite.ts
import { inngest } from "@/server/jobs/client";
import { sendInvite } from "@/server/email/send";