Background Jobs & Workflows in Next.js with Trigger.dev v3
Run long tasks, retries, scheduled CRON jobs, and webhook processing in Next.js using Trigger.dev v3 — without timing out serverless functions.

Serverless functions are great for request-response work and terrible for anything that takes more than a few seconds — video processing, bulk imports, multi-step AI pipelines, or scheduled reports. Trigger.dev v3 gives Next.js apps a proper background job runtime: long-running tasks, automatic retries, CRON scheduling, and webhook-safe processing, without you managing a queue or worker infrastructure yourself.
Step 1: Install and Configure Trigger.dev
This scaffolds a trigger/ directory and a trigger.config.ts file, and links your project to a Trigger.dev instance.
Step 2: Define a Long-Running Task
This task can run for minutes without hitting any serverless timeout, because it executes on Trigger.dev's infrastructure, not inside your Next.js deployment.
Step 3: Trigger the Task from a Server Action
The Server Action returns immediately with a runId — the user's request isn't blocked waiting for transcoding to finish. You can poll or subscribe to that run's status separately if you need to show progress in the UI.
Step 4: Add Scheduled CRON Jobs
No separate cron service, no always-on server, and no reliance on a serverless platform's own (often unreliable) scheduled function trigger — Trigger.dev's infrastructure fires this task on the defined schedule.
Step 5: Process Webhooks Safely
Most webhook providers retry aggressively if your endpoint doesn't respond within a few seconds — so validate and hand off immediately, then do the real work in a task.
The webhook handler's only job is signature verification and enqueueing — it responds in milliseconds regardless of how long fulfillOrder actually takes.
Step 6: Chain Multi-Step Workflows
Each step runs sequentially with the same retry semantics as any other task — if sendWelcomeEmail fails transiently, only that step retries, not the whole onboarding flow from scratch (when using triggerAndWait for sub-tasks instead of inline calls).
Key Takeaways
Trigger.dev tasks run outside your Next.js deployment's execution limits, so long tasks like transcoding or bulk sync never risk a serverless timeout. Trigger tasks from Server Actions with tasks.trigger() and return immediately, lean on built-in retry.maxAttempts instead of hand-rolled retry loops, use schedules.task() for CRON work, and always acknowledge webhooks fast by enqueueing a task rather than processing inline.






