This document provides a high-level introduction to the Trigger.dev codebase, its purpose as a background jobs and task execution platform, and the overall system architecture. This page covers the platform's core components, package organization, and architectural patterns.
For detailed information about specific subsystems, see:
Sources: README context from diagrams pnpm-lock.yaml1-10 package.json1-20
Trigger.dev is a background jobs platform that enables developers to define, schedule, and execute long-running tasks with built-in reliability, observability, and scaling capabilities. The platform handles task orchestration, retry logic, distributed locking, concurrency management, and state persistence, allowing developers to focus on business logic.
The system operates as a multi-tenant SaaS platform (cloud.trigger.dev) or can be self-hosted. Tasks are defined using the @trigger.dev/sdk package in TypeScript, deployed as Docker containers, and executed in isolated worker environments managed by the platform.
Core Value Proposition:
task() function with TypeScriptSources: packages/trigger-sdk/package.json1-10 apps/webapp/package.json1-10
Architecture: Trigger.dev follows a layered monorepo architecture managed by pnpm workspaces and Turborepo. The codebase separates concerns into three primary tiers:
apps/webapp Remix application serving both API and web dashboardSources: package.json4-8 turbo.json1-20 apps/webapp/app/root.tsx1-30 apps/webapp/server.ts1-20
The central nerve center of the platform, built with Remix 2.1.0 and Express 4.20.0.
The webapp serves dual roles:
Key Files:
Sources: apps/webapp/package.json1-50 apps/webapp/server.ts1-200 apps/webapp/app/root.tsx1-133
Coordinator (apps/coordinator): Lightweight service that routes task execution requests to appropriate supervisors. Uses Socket.IO for real-time communication with the platform core.
Supervisor (apps/supervisor): Manages the lifecycle of worker containers/pods. Supports both Kubernetes (via @kubernetes/client-node) and Docker (via dockerode) as compute providers. Pulls Docker images from ECR registries and instantiates worker environments.
Run Engine 2.0 (internal-packages/run-engine): The core task execution orchestrator introduced in v4. Features:
Configuration (from apps/webapp/app/env.server.ts560-583):
Sources: apps/coordinator/tsconfig.json1-20 apps/supervisor/tsconfig.json1-20 apps/webapp/app/env.server.ts560-600
@trigger.dev/sdk (packages/trigger-sdk): The primary developer interface. Exports:
task() - Define tasks with retry, queue, and lifecycle optionsschemaTask() - Type-safe tasks with Zod validationtrigger(), batchTrigger() - Programmatically trigger task executionwait, metadata, usage - Runtime utilitiestrigger.dev (packages/cli-v3): Command-line interface for:
dev - Local development server with hot reloaddeploy - Build and deploy tasks to productionlogin, logout, whoami - Authentication@trigger.dev/cli-v3 as internal package name, published as trigger.dev@trigger.dev/core (packages/core): Shared code used across SDK, CLI, and platform. Contains Zod schemas, OpenTelemetry configuration, IPC protocols, and runtime utilities.
Sources: packages/trigger-sdk/package.json1-50 packages/cli-v3/package.json1-50 packages/core/package.json1-50
Trigger.dev uses a three-tier storage strategy optimized for different data access patterns:
PostgreSQL (via Prisma ORM at internal-packages/database/prisma/schema.prisma1-100):
ClickHouse (via internal-packages/clickhouse):
Redis Cluster (9 instances, configured in apps/webapp/app/env.server.ts119-472):
Sources: internal-packages/database/prisma/schema.prisma1-100 apps/webapp/app/env.server.ts52-250 internal-packages/clickhouse/package.json1-20
The monorepo is organized using pnpm workspaces with three workspace categories defined in package.json4-8:
Workspace Categories:
apps/* - Deployable applications
packages/* - Published to npm registry
internal-packages/* - Shared internal code
Build Orchestration: Turborepo (turbo.json1-50) manages build pipelines with dependency-aware caching:
Sources: package.json4-10 turbo.json1-50 pnpm-lock.yaml45-107
Deployment Flow:
trigger.dev deploy (packages/cli-v3/package.json34)--local-build) - Uses Docker Buildx on developer machine--native-build-server) - Backend-orchestrated builds with S2 log streamingRegistry Configuration (apps/webapp/app/env.server.ts294-333):
DEPLOY_REGISTRY_HOSTV4_DEPLOY_REGISTRY_HOSTSources: packages/cli-v3/package.json1-50 apps/webapp/app/env.server.ts294-350 apps/kubernetes-provider/tsconfig.json1-20 apps/docker-provider/tsconfig.json1-20
Decision: Use PostgreSQL for transactional data, ClickHouse for analytics, and 9 specialized Redis instances for different caching/coordination patterns.
Rationale: Each storage system is optimized for its use case:
Implementation: apps/webapp/app/env.server.ts119-472
Decision: Replace previous job queue system with custom Run Engine featuring queue sharding, worker pools, and sophisticated queue selection.
Rationale:
Implementation: apps/webapp/app/env.server.ts560-583
Decision: Use pnpm workspaces with clear boundaries between published packages, internal packages, and applications.
Rationale:
Implementation: package.json4-8 turbo.json1-50
Decision: Build webapp as Remix application hosted by Express server, serving both API and dashboard.
Rationale:
Implementation: apps/webapp/server.ts1-200 apps/webapp/app/root.tsx1-133
Sources: apps/webapp/package.json1-50 apps/webapp/server.ts1-200 apps/webapp/app/env.server.ts1-100
This overview provides the foundation for understanding Trigger.dev's architecture. For detailed information on specific subsystems, refer to the linked sections: SDK and CLI (#3), Task Execution (#4), Web Application (#5), Database (#6), and Deployment (#7).
Refresh this wiki
This wiki was recently refreshed. Please wait 7 days to refresh again.