Skip to content

How It Works

Trigger.dev lets you integrate long-running async tasks into your application and run them in the background — no timeouts, elastic scaling, zero infrastructure management.

Example: Video Processing Task

ts
// /trigger/video.ts
import { logger, task } from "@trigger.dev/sdk";
import ffmpeg from "fluent-ffmpeg";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

export const convertVideo = task({
  id: "convert-video",
  retry: { maxAttempts: 5, minTimeoutInMs: 1000, maxTimeoutInMs: 10000, factor: 2 },
  run: async ({ videoId }: { videoId: string }) => {
    // ... process video with ffmpeg, upload to S3, send email
    return { success: true, s3Url };
  },
});

Trigger it from your API route:

ts
import { tasks } from "@trigger.dev/sdk";
import type { convertVideo } from "./trigger/video";

export async function POST(request: Request) {
  const body = await request.json();
  const handle = await tasks.trigger<typeof convertVideo>("convert-video", body);
  return Response.json(handle);
}

The CLI

bash
npx trigger.dev@latest login    # Authenticate
npx trigger.dev@latest init     # Initialize in your project
npx trigger.dev@latest dev      # Run tasks locally
npx trigger.dev@latest deploy   # Deploy to Trigger.dev

Supports multiple profiles for switching between accounts or self-hosted instances.

Architecture

Trigger.dev uses a serverless architecture (without timeouts). When you deploy, task code is built and uploaded to your instance. When triggered, tasks run in secure isolated environments.

The Checkpoint-Resume System

Enables efficient long-running tasks in a serverless environment:

  1. Task Execution — runs in isolated environment with all resources
  2. Subtask Handling — trigger subtasks with triggerAndWait()
  3. State Checkpointing — uses CRIU to checkpoint state while waiting
  4. Resource Release — parent task resources released during wait
  5. Efficient Storage — checkpoint compressed and stored on disk
  6. Event-Driven Resumption — subtask completion triggers restoration
  7. Seamless Continuation — task resumes exactly where it left off
ts
export const parentTask = task({
  id: "parent-task",
  run: async () => {
    const result = await childTask.triggerAndWait({ data: "some data" });
    await wait.for({ seconds: 30 }); // checkpointed, no resource consumption
    return "Parent task completed";
  },
});

No charge for wait time

In Trigger.dev Cloud, you're not charged for time spent waiting for subtasks or in a paused state.

Durable Execution

  1. Complex workflows broken into smaller independent subtasks
  2. Each subtask assigned a unique idempotency key
  3. Results cached by idempotency key
  4. On failure: only failed subtask and subsequent tasks are retried

Build System

Powered by esbuild:

  • Bundled by default — code + dependencies bundled and tree-shaked
  • Build extensions — customize the build process or container image
  • ESM output — enables tree-shaking and better performance

Dev Mode

npx trigger.dev@latest dev:

  • Same build system as production
  • Auto-detects changes and re-registers tasks
  • Supports debuggers and breakpoints
  • Each task runs in a separate process
  • Auto-cancels tasks when dev server stops

OpenTelemetry

Dashboard powered by OpenTelemetry traces and logs. Auto-instrument with:

ts
// trigger.config.ts
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { AwsInstrumentation } from "@opentelemetry/instrumentation-aws-sdk";

export default defineConfig({
  project: "<project-ref>",
  instrumentations: [new PrismaInstrumentation(), new AwsInstrumentation()],
});

Built from official Trigger.dev documentation