Background jobs in JavaScript have always been painful. BullMQ needs Redis. Cron needs infrastructure. Trigger.dev just works — write a function, it runs in the background.
What is Trigger.dev?
Trigger.dev is an open-source platform for running background jobs, scheduled tasks, and long-running workflows in TypeScript. Think of it as "Vercel for background jobs."
Why Trigger.dev Solves Real Problems
1. Define Jobs as TypeScript Functions
import { task } from "@trigger.dev/sdk/v3";
export const processVideo = task({
id: "process-video",
run: async (payload: { videoUrl: string; userId: string }) => {
// Download video
const video = await downloadVideo(payload.videoUrl);
// Generate thumbnail
const thumbnail = await generateThumbnail(video);
// Transcribe
const transcript = await transcribeAudio(video);
// Save results
await db.videos.update({
where: { userId: payload.userId },
data: { thumbnail, transcript, status: "processed" },
});
return { success: true };
},
});
2. Trigger from Your App
// From your Next.js API route, Express handler, etc.
import { processVideo } from "@/trigger/process-video";
export async function POST(req: Request) {
const { videoUrl, userId } = await req.json();
// Trigger background job
const handle = await processVideo.trigger({ videoUrl, userId });
return Response.json({ jobId: handle.id });
}
3. Scheduled Tasks (Cron)
import { schedules } from "@trigger.dev/sdk/v3";
export const dailyReport = schedules.task({
id: "daily-report",
cron: "0 9 * * *", // 9 AM daily
run: async () => {
const stats = await db.getYesterdayStats();
await sendSlackMessage(`Daily report: ${stats.revenue} revenue, ${stats.signups} signups`);
},
});
4. Long-Running Tasks (Up to 5 Hours)
export const aiPipeline = task({
id: "ai-pipeline",
maxDuration: 300, // 5 minutes
run: async (payload: { documents: string[] }) => {
const results = [];
for (const doc of payload.documents) {
// Each step can take minutes
const embedding = await generateEmbedding(doc);
const analysis = await analyzeWithGPT4(doc);
results.push({ embedding, analysis });
}
return results;
},
});
5. Retry and Error Handling
export const sendEmail = task({
id: "send-email",
retry: {
maxAttempts: 3,
factor: 2,
minTimeoutInMs: 1000,
maxTimeoutInMs: 30000,
},
run: async (payload: { to: string; subject: string; body: string }) => {
await emailService.send(payload);
},
});
6. Dashboard and Observability
Real-time dashboard shows:
- Job status (running, completed, failed)
- Execution timeline
- Logs and errors
- Retry history
- Performance metrics
Trigger.dev vs BullMQ vs Inngest
| Trigger.dev | BullMQ | Inngest | |
|---|---|---|---|
| Infrastructure | Managed/self-host | Redis required | Managed/self-host |
| Language | TypeScript | Node.js | TypeScript |
| Cron | Built-in | Via separate setup | Built-in |
| Dashboard | Built-in | Bull Board (separate) | Built-in |
| Max duration | 5 hours | Unlimited | 1 hour |
| Retries | Built-in | Built-in | Built-in |
| Self-hosted | Yes | Yes | Yes |
Free Tier
| Feature | Free |
|---|---|
| Runs/month | 10,000 |
| Concurrent jobs | 5 |
| Log retention | 7 days |
| Cron jobs | 5 |
Getting Started
npx trigger.dev@latest init
npx trigger.dev@latest dev
The Bottom Line
Trigger.dev makes background jobs as easy as writing a function. No Redis, no queue infrastructure, no cron servers. Write TypeScript, it runs in the background.
Need data tools? I build web scraping solutions. Check my Apify actors or email spinov001@gmail.com.
Top comments (0)