Scheduled jobs on serverless hosting: replacing the crontab
Short answer: On serverless hosting there's no server to log into and no crontab, so nightly stock syncs, reminder emails and clean-up jobs need the platform's own scheduler. Most platforms offer one: they call your function or an HTTP endpoint on a cron-style schedule, usually in UTC. Write each job so it finishes within the platform's time limit or hands work to a queue, protect any HTTP endpoint so outsiders can't trigger it, make it safe to run twice, and add monitoring so you notice when it stops. Check the docs for your platform, as features and names change.
Why the old approach doesn't work
On a traditional server, you'd add a line to the crontab and the operating system would run your script on schedule. Serverless platforms run your code only when a request or event arrives, on machines you don't control. There's nowhere to put a crontab, and nothing runs in the background between requests.
Teams moving from a server sometimes discover this weeks later, when reminder emails or invoice exports quietly stopped after the migration.
What platforms offer
Most serverless and edge platforms provide scheduled triggers. Two examples from current documentation:
- Vercel documents Cron Jobs, where Vercel makes an HTTP GET request to your project's production deployment URL at the path set in your configuration, and notes that the timezone is always UTC. Its documentation now labels Cron Jobs a legacy feature to be migrated to a newer Schedules feature, which adds timezones and other targets. If you're on Vercel, check which one your project should use.
- Cloudflare Workers documents Cron Triggers, which map a cron expression to a Worker's
scheduled()handler and execute on UTC time. It notes that changes to triggers can take several minutes, up to 15, to propagate.
Other clouds offer equivalents, such as scheduled functions or scheduler services that call an endpoint or start a function.
Step 1: Translate your schedule to UTC
If a job should run at 6:00 in Dublin, remember that Ireland's offset from UTC changes during the year. With a UTC-only scheduler you can:
- choose a UTC time that's acceptable in both summer and winter;
- run hourly and let the code decide whether it's the right local time;
- or use a scheduler that supports time zones, if your platform offers one.
Step 2: Fit the time limit
Serverless functions have maximum run times. A job that processes every customer in one go may be cut off halfway. Options:
- Process in batches: handle a fixed number of records each run and pick up where you left off.
- Fan out to a queue: the scheduled function lists the work and puts each item on a queue for separate workers.
- Use a longer-running service for genuinely heavy jobs.
Record progress so a cut-off run doesn't start from scratch every time.
Step 3: Protect HTTP-triggered jobs
If the scheduler calls a public URL like /api/cron/send-reminders, anyone who discovers that URL could trigger it. Protect it:
- Require a secret token in a header, stored as an environment variable, and reject requests without it.
- Check any platform-provided header or signature, if your platform documents one.
- Rate limit the endpoint.
Never put sensitive actions behind an unprotected URL.
Step 4: Make jobs safe to repeat
Scheduled triggers can occasionally run twice, run late, or be retried after an error. Design each job so a second run doesn't double-send emails or double-charge:
- Mark records as processed in the same step as processing them.
- Use unique keys for outgoing actions, such as one reminder per booking per day.
- Use a lock if two runs mustn't overlap.
Step 5: Watch it
A job that silently stops is worse than one that fails loudly.
- Log the start, end and number of items processed for each run.
- Send an alert if a run fails.
- Use a heartbeat check: the job pings a monitoring service at the end, and you're alerted if the ping doesn't arrive on time.
- Check preview or staging environments: some schedulers only run on production, which is usually what you want, but confirm it.
Keep a list of every scheduled job
Write down each job in one place: what it does, its schedule in UTC and local time, where it's configured, what secret it uses, and who to contact if it fails. Scheduled work is easy to forget because nobody sees it run. When you migrate hosting, change frameworks or hand the site to a new developer, that list is how you check nothing was left behind.
Test locally and after deploys
Schedulers don't run on your laptop, so make each job callable manually in development, with the same protection. After each deploy, check the platform's dashboard or logs to confirm the schedule is still registered; configuration files can be overwritten or a renamed endpoint can leave the scheduler calling a path that no longer exists. Cloudflare's note that trigger changes can take up to 15 minutes to propagate is a reminder not to panic if a new schedule doesn't fire immediately.
An illustrative example
A hypothetical Cork physiotherapy clinic moved its booking site from a virtual server to a serverless platform. Appointment reminder texts stopped, because the old crontab no longer existed. The developer added a platform schedule calling a protected endpoint hourly, with the code sending reminders for appointments 24 hours ahead in Irish local time, marking each reminder as sent so a repeated run couldn't send duplicates, and pinging a heartbeat monitor at the end of each run.
FAQ
Can I use a free external cron service to call my URL?
You can, but protect the endpoint and consider reliability. Your platform's scheduler is usually simpler.
Why didn't my job run in my preview deployment?
Many schedulers only trigger production. Check your platform's documentation.
How often can jobs run?
It depends on the platform and plan. Check current limits.
Do I still need a queue?
For small jobs, no. For large batches or slow third-party APIs, a queue is safer.
If your scheduled jobs stopped after moving to serverless hosting, tell us which platform and jobs.