Decorative background gradient
Back to Blog
Trigger.dev TutorialNextjs Background JobsServerless Task Queue Nodejs

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.

Background Jobs & Workflows in Next.js with Trigger.dev v3

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

bash

This scaffolds a trigger/ directory and a trigger.config.ts file, and links your project to a Trigger.dev instance.

ts

Step 2: Define a Long-Running Task

ts

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

tsx

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

ts

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.

ts
ts

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

ts

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.

Frequently Asked Questions

Why not just use a Vercel serverless function for background jobs?

Serverless functions have hard execution time limits (10-60s on most plans) and are meant for request-response work, not long tasks like video processing or bulk data sync. Trigger.dev runs tasks on dedicated infrastructure with no such limit, and gives you retries, observability, and queuing that a raw serverless function doesn't.

How do retries work in Trigger.dev?

Set retry.maxAttempts (and optionally minTimeoutInMs/maxTimeoutInMs) on a task definition. If the task throws, Trigger.dev automatically re-runs it with exponential backoff up to the configured attempt count, without you writing retry-loop code.

Can Trigger.dev replace a traditional CRON job?

Yes. schedules.task() lets you attach a CRON expression directly to a task definition, and Trigger.dev's infrastructure triggers it on that schedule — no separate cron service, serverless cron trigger, or always-on server process required.

How should I handle incoming webhooks with Trigger.dev?

Validate the webhook signature in your Route Handler, then immediately call tasks.trigger() to hand the payload off to a background task and return a 200 response right away. Do the actual processing inside the task — most webhook providers retry aggressively if your endpoint doesn't respond within a few seconds.

Working on something similar? Take a look at my services and case studies, or book a free call to talk about your idea.

Related Articles

Silent Tool Failures in AI Agents — Why Your Agent Lies About Success
Ai Agent ReliabilityTool Call FailuresLlm Error Handling+1 more

Silent Tool Failures in AI Agents — Why Your Agent Lies About Success

Most AI agent bugs never throw an error — the tool call "succeeds" with empty, truncated, or stale data and the agent confidently reports the task as done. Here's how to catch failures that don't look like failures.

September 22, 2026Read more →
AI Coding Agents Compared in 2026 — Claude Code vs Cursor vs GitHub Copilot
Claude Code Vs CursorAI Coding AgentsGithub Copilot

AI Coding Agents Compared in 2026 — Claude Code vs Cursor vs GitHub Copilot

Compare Claude Code, Cursor, and GitHub Copilot for real development work — agentic workflows, codebase understanding, pricing, and which fits your team.

September 18, 2026Read more →
Best Authentication Libraries for Next.js in 2026 — Clerk vs Auth.js vs Better Auth
Nextjs AuthenticationClerk Vs NextauthBetter Auth

Best Authentication Libraries for Next.js in 2026 — Clerk vs Auth.js vs Better Auth

Compare Clerk, Auth.js (NextAuth), and Better Auth for Next.js — setup effort, hosted UI, pricing, and which fits your app.

September 18, 2026Read more →
Best Error Monitoring & Analytics Tools for Next.js in 2026 — Sentry vs PostHog vs Vercel Analytics
Nextjs Error MonitoringSentry Vs PosthogWeb Analytics

Best Error Monitoring & Analytics Tools for Next.js in 2026 — Sentry vs PostHog vs Vercel Analytics

Compare Sentry, PostHog, and Vercel Analytics for a Next.js app — error tracking, product analytics, session replay, and pricing.

September 18, 2026Read more →
How to Add AI Features to an Existing Web App (Without a Rebuild)
Add AI To Existing AppAI SaaS FeaturesOpenAI API Integration

How to Add AI Features to an Existing Web App (Without a Rebuild)

A practical guide to adding real AI features, like matching, extraction, and automation, to a web app or SaaS product you already have, without rebuilding it from scratch.

September 16, 2026Read more →
AI Agent Observability and Tracing in Production
Ai Agent ObservabilityLlm TracingAgent Monitoring+2 more

AI Agent Observability and Tracing in Production

Why logging inputs and outputs isn't enough for AI agents in production — and how trace-level observability catches failures evals and logs miss.

September 14, 2026Read more →

Trending Topics