Thomas Osayi

November 23, 2026 · 9 min read · Thomas Osayi

Cron jobs and background jobs in Next.js on Vercel: setup, security, limits and queues

How to run cron jobs in Next.js on Vercel: vercel.json setup, plan limits, CRON_SECRET, function duration, Vercel Schedules, queues, Firebase and idempotent jobs.

Every SaaS ends up with work that nobody clicks a button for: a nightly report, an hourly sync from Shopify, a reminder email the day before a booking, a cleanup of expired trials. In a Next.js app on Vercel, the first tool for that is a cron job, and it is simpler than most people expect. The trouble starts when a job takes longer than a function is allowed to run, fails silently, or runs twice and charges someone twice.

This post covers how Vercel cron jobs work, the limits on each plan at the time of writing, how to secure them with CRON_SECRET, what to do when a job outgrows a single function, which queue services to look at, the Firebase alternative, and how to make jobs safe to repeat.

How do cron jobs work in Next.js on Vercel?

A Vercel cron job is an ordinary route in your app that Vercel calls with a GET request on the schedule you define, so the job is just code in a route handler.

There is no separate worker or server. You write a route handler, for example app/api/cron/daily-digest/route.ts, that does the work and returns a response. You tell Vercel when to call it. At the scheduled time, Vercel sends a request to that path on your production deployment, the route runs like any other Vercel Function, and the result shows up in your logs.

A few behaviours follow from that design, and all of them come from Vercel's docs at the time of writing:

  • Cron jobs run only on production deployments, never on previews.
  • They are billed and limited like any other function invocation.
  • They do not follow redirects, so a 3xx response ends the run.
  • A cached response or a redirect does not appear in the logs, so mark cron routes dynamic with export const dynamic = 'force-dynamic'.
  • You can trigger a route by hand locally by visiting it, such as http://localhost:3000/api/cron/daily-digest, because it is just a route.

One more thing changed recently. Vercel's docs now label Cron Jobs a legacy feature that will be migrated to Vercel Schedules, which adds time zones, private function targets, queue targets and schedules created at runtime. Schedules is in public beta at the time of writing. Existing cron jobs keep working, and the route code stays the same when you migrate.

How do you set up a cron job in vercel.json?

Add a crons array to vercel.json with one entry per job, each with a path to your route and a schedule written as a cron expression in UTC.

The configuration has two fields per job:

  • path: the route to call, which must start with a slash, such as /api/cron/daily-digest.
  • schedule: a five-part cron expression, such as 0 13 * * * for 13:00 UTC every day.

After you deploy to production, the job appears in the project dashboard under Schedules, on the Cron Jobs tab, where you can view logs and disable all cron jobs for the project. To change a schedule, edit vercel.json and redeploy. To delete a job, remove its entry and redeploy.

Remember that the schedule is UTC. 13:00 UTC is 5am or 6am in Los Angeles depending on daylight saving, which matters for anything customer-facing like a morning summary email.

Two gotchas I have hit. If next.config.js has trailingSlash enabled, a request to /api/cron/daily-digest redirects to the same path with a trailing slash, and the cron job never reaches your function. Put the trailing slash in the path. And if a firewall rule challenges unknown traffic, it can block the cron request before your code runs, so exclude cron paths from those rules.

What are the limits on each Vercel plan?

At the time of writing, every plan allows 100 cron jobs per project, but Hobby jobs can run only once a day within the scheduled hour, while Pro and Enterprise jobs can run every minute with per-minute precision.

Cron Jobs

  • Hobby: up to 100 cron jobs per project; minimum interval once per day; timing anywhere within the scheduled hour, so a 1am job can fire up to 1:59am. An expression that runs more often fails at deploy with "Hobby accounts are limited to daily cron jobs."
  • Pro and Enterprise: up to 100 per project; every minute at the most; invoked within the scheduled minute.

Vercel Schedules (public beta)

  • Hobby: up to 1,000 schedules per team, at most every 15 minutes with a fixed 15-minute jitter window, and up to 5,000 runs per billing period.
  • Pro: up to 10,000 schedules per team, as often as every minute with a default 1-minute jitter window.
  • Schedules can target a private function or a queue, not only a public path.

Duration is the other limit. A cron run is a function invocation, so on Fluid compute it gets 300 seconds by default, with Pro able to raise that to 800 seconds and an extended 1,800 seconds in beta. "Vercel function timeout (FUNCTION_INVOCATION_TIMEOUT): causes and fixes" covers how to raise maxDuration and what to do when that is not enough.

How do you secure a cron route with CRON_SECRET?

Add an environment variable named CRON_SECRET to the project, and in the route reject any request whose Authorization header is not the word Bearer, a space, and that secret.

Without this, anyone who guesses the path can trigger your job. Vercel sends the CRON_SECRET value automatically as a Bearer token when it calls the route. The check inside the handler is short:

  • Read the authorization header from the request.
  • Read process.env.CRON_SECRET.
  • If the secret is missing, or the header does not equal Bearer followed by a space and the secret, return a 401 and stop.
  • Only then run the job.

Vercel's guidance at the time of writing is a random string of at least 16 characters, using only characters valid in a header, such as letters and numbers. Watch for a trailing space or line break when you paste it, because that produces a 401 on every run.

Each deployment captures CRON_SECRET when it builds. Editing the variable changes nothing until you redeploy, and an Instant Rollback brings back the older deployment's secret along with its code. To rotate, update the variable, redeploy, then check the first run's log for a 2xx status.

What happens when a job takes longer than the function limit?

When a cron run reaches the function's maximum duration it stops with a timeout, so long jobs need to be split into batches or handed to a queue or workflow that can retry and resume.

The patterns, from simplest to most robust:

  • Process a batch per run: handle the oldest 200 records, save progress, and let the next run continue. Running every few minutes on Pro clears a backlog steadily.
  • Fan out: the cron route only finds the work and publishes one message per item to a queue, and a consumer handles each item in its own invocation.
  • Use a workflow engine for multi-step jobs that wait, call external APIs and need retries.

Vercel's own options at the time of writing are Vercel Queues (public beta), which offers retries and messages kept for up to 7 days, and Vercel Workflows, generally available since April 2026, where a run has no overall duration limit but each step is still bound by the function maximum.

Which queue or background job service should you use?

Use Vercel's built-in queues and workflows if you want everything on one bill, or a dedicated service such as Inngest, Trigger.dev or QStash when you want mature retries, dashboards and scheduling across hosts.

Vercel Queues and Workflows

  • Best for: apps already on Vercel that want queues and durable steps without another vendor.
  • Cost range: Queues are billed per API operation, with the first 1,000,000 included on Hobby at the time of writing; workflow events are included up to 50,000 a month on Hobby.
  • Pros: one platform; same deployments and environment variables; Schedules can target a queue directly.
  • Cons: Queues is still in public beta; no built-in dead-letter queue.

Inngest

  • Best for: event-driven background functions with step-level retries.
  • Cost range: free Hobby plan with 50,000 executions a month at the time of writing; Pro from $99 a month.
  • Pros: steps, retries, throttling and a clear run history.
  • Cons: another service to configure and monitor.

Trigger.dev

  • Best for: long-running tasks, such as AI pipelines or video processing, that would exceed function limits.
  • Cost range: Free with $5 of monthly usage credit and 10 schedules; Hobby $10 a month; Pro $50 a month, at the time of writing.
  • Pros: its pricing page states runs have no maximum duration; built-in schedules and concurrency controls.
  • Cons: usage-based compute to budget for.

Upstash QStash

  • Best for: simple HTTP message delivery and schedules with very little setup.
  • Cost range: 1,000 messages a day free; pay as you go at $1 per 100,000 messages, at the time of writing.
  • Pros: works from any host; calls your existing routes.
  • Cons: you still write the handler logic and idempotency yourself.

What about Firebase scheduled functions?

If your backend is Firebase, a scheduled Cloud Function is the natural alternative to Vercel cron, with the job running inside Google Cloud next to Firestore.

You write the job with onSchedule from firebase-functions/v2/scheduler, passing either crontab syntax or a phrase such as "every day 00:00", and deploy it with the rest of your functions. Under the hood, Firebase creates a Cloud Scheduler job for each one.

Costs at the time of writing: Cloud Functions are not available on the free Spark plan, so you need the pay-as-you-go Blaze plan. Cloud Scheduler charges $0.10 per job per month, with three jobs free per billing account, not per project. Invocations come out of the Blaze free allowance of 2 million a month before you pay per call.

This keeps scheduled work beside your data and Firebase Admin credentials, and off your Next.js host entirely. NOM, the food discovery app I built, runs on Firebase, and for a Firebase product I would keep scheduled work in Firebase too rather than splitting it across platforms.

How do you make jobs safe to run twice?

Make every job idempotent, which means running it twice has the same effect as running it once, and reconciliation-based, which means it picks up everything outstanding since the last success.

Vercel's docs say plainly that cron delivery is best effort: a run can be missed, and the same scheduled run can occasionally be invoked more than once. A job that overlaps its own next run can also start twice. So design for it:

  • Prefer "set status to sent" over "add one to the sent count".
  • Store a unique key for each unit of work, such as the booking ID plus the reminder date, and skip anything already done.
  • Query for everything not yet processed instead of "everything from the last hour", so a missed run catches up.
  • Use a lock, such as a Redis key with an expiry, to stop two runs working at once.
  • Record each run's start, finish and item count in a table so you can see gaps.

As an illustration, picture a booking app that emails reminders the day before an appointment. The cron job runs hourly on Pro, selects bookings for tomorrow where reminder_sent_at is empty, sends each email with an idempotency key, and sets reminder_sent_at. If a run is missed, the next one sends the backlog. If a run is duplicated, nothing sends twice.

The bottom line

Cron jobs in Next.js on Vercel are routes on a schedule: define them in vercel.json, protect them with CRON_SECRET, mark them dynamic, and remember they run only in production. At the time of writing, Hobby runs once a day and Pro every minute, each run is capped by the function's maximum duration, and Vercel does not retry failures. Batch the work, move long jobs to Queues, Workflows, Inngest, Trigger.dev or QStash, and make every job safe to run twice. If you want a scheduled job built properly into an existing app, my Fix Plus Features package from $200 covers it.

Questions, answered in one line

Do Vercel cron jobs run on preview deployments?

No, Vercel invokes cron jobs only on the production deployment, so you test the route by calling it directly on a preview or locally.

How often can a cron job run on the Vercel Hobby plan?

At the time of writing Hobby cron jobs can run once per day and may fire anywhere within the scheduled hour, while Pro and Enterprise can run every minute.

What is CRON_SECRET on Vercel?

CRON_SECRET is an environment variable you add to your project, and Vercel sends its value as a Bearer token in the Authorization header so your route can reject anyone else.

What happens if my cron job takes too long?

The run stops at the function's maximum duration with a timeout error, so split the work into batches or hand it to a queue or workflow service.

Does Vercel retry a failed cron job?

No, Vercel does not retry a failed cron invocation, so your job should catch up on outstanding work the next time it runs.

Can Thomas Osayi set up scheduled jobs for my app?

Thomas Osayi's Fix Plus Features package, from $200 in about 5 days, covers up to three fixes plus one small feature such as a secured nightly sync job.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

SaaS MVP and full-stack web app development

I build SaaS MVPs and full-stack web apps in Next.js, TypeScript and Firebase or Postgres: auth, dashboards, payments, roles and admin tools. Founder of SQWAD.

See the service