Background Jobs for Next.js
The easiest way to run background jobs in Next.js. Define type-safe jobs with a TypeScript API, add retries and scheduling, and start processing in minutes. Works with Vercel, serverless, and any Node.js hosting.
Overview
Your job processing at a glance
1,247
1,198
12
340ms
Everything you need to process background jobs
A type-safe job queue for Next.js and TypeScript. Read the docs to learn more.
Type-Safe by Default
A tRPC-inspired TypeScript API with Zod validation. Full type safety from job definition to enqueue — catch errors at build time, not runtime.
Runs on Your Infrastructure
Jobs execute in your own app via a callback model. No vendor lock-in for execution, no cold starts, full access to your database and services.
Automatic Retries
Failed jobs are automatically retried with configurable exponential or linear backoff. Set max attempts, delays, and backoff strategies per job.
Real-Time Monitoring
Track job status, view run history, and monitor performance from the Queuebase dashboard. See what's running, what succeeded, and what needs attention.
CRON Scheduling
Coming soonSchedule recurring jobs with familiar CRON syntax. Perfect for reports, data syncs, and cleanup tasks.
Webhook Notifications
Coming soonGet notified via webhooks when jobs complete, fail, or need attention. Integrate with Slack, PagerDuty, or any HTTP endpoint.
Get started in minutes
Inspired by the developer experience of tRPC and UploadThing. Define your jobs, create a handler, and start processing — all with full type safety.
import { createJobRouter, job } from '@queuebase/nextjs';
import { z } from 'zod';
export const jobs = createJobRouter({
sendEmail: job({
input: z.object({
to: z.string().email(),
subject: z.string(),
body: z.string(),
}),
handler: async ({ input, jobId, attempt }) => {
console.log(`Sending email to ${input.to}`);
await sendEmail(input);
return { sent: true };
},
defaults: {
retries: 3,
backoff: 'exponential',
},
}),
});
export type JobRouter = typeof jobs; Define your jobs
Define your jobs using a tRPC-style router. Each job has a Zod schema for input validation and a handler function that runs when the job executes.
import { createHandler } from '@queuebase/nextjs/handler';
import { jobs } from '@/jobs';
export const POST = createHandler(jobs); Create your API handler
Expose a POST endpoint that Queuebase calls to execute your jobs. One line of code — the handler takes care of routing, validation, and execution.
import { createClient } from '@queuebase/nextjs';
import { jobs } from './index';
export const jobClient = createClient(jobs, {
apiUrl: process.env.QUEUEBASE_API_URL!,
apiKey: process.env.QUEUEBASE_API_KEY,
callbackUrl: process.env.QUEUEBASE_CALLBACK_URL!,
}); Create your client
The client gives you type-safe access to enqueue jobs from anywhere in your app — server components, server actions, or API routes.
'use server';
import { jobClient } from '@/jobs/client';
export async function sendWelcomeEmail() {
await jobClient.sendEmail.enqueue({
to: 'user@example.com',
subject: 'Welcome to our app!',
body: 'Thanks for signing up.',
});
} Enqueue a job
Enqueue jobs with full type safety. Your IDE autocompletes job names, validates input shapes, and catches errors at build time.
Frequently asked questions
Can't find what you're looking for? Reach out on Twitter or email support@queuebase.com .
How do I run background jobs in Next.js?
Can I use Queuebase with Vercel?
Does Queuebase support retries and error handling?
Does Queuebase support CRON jobs?
Does Queuebase work with the Next.js App Router and Pages Router?
Do I have to use Next.js?
How much does Queuebase cost?
How does Queuebase compare to Inngest, Trigger.dev, and BullMQ?
Who’s behind Queuebase?
Start running background jobs today
Start with 10,000 free job runs per month. No credit card required.