Prompt
How do I run cron jobs in a serverless setup?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
Cron jobs in a serverless setup are usually replaced by a scheduler + function pattern:
- A managed scheduler triggers on a schedule
- It invokes a serverless function
- The function runs the task and exits
Common options
Cloud provider schedulers
- AWS: EventBridge Scheduler / EventBridge Rules → Lambda, ECS task, SQS, Step Functions
- Google Cloud: Cloud Scheduler → Cloud Functions / Cloud Run / Pub/Sub
- Azure: Timer-triggered Azure Functions / Logic Apps / Durable Functions
- Vercel / Netlify / Firebase: built-in cron/scheduled functions depending on platform
External schedulers
If your platform doesn’t provide one, use:
- GitHub Actions on a schedule
- Upstash QStash / cron
- cron-job.org
- a separate worker service
- Kubernetes CronJobs if you’re in a container platform
Best practice pattern
For anything non-trivial, do this:
- Scheduler triggers a lightweight endpoint or queue
- Function enqueues work or starts a workflow
- Background worker processes the actual job
This avoids:
- timeouts
- duplicate runs
- cold-start issues
- long-running process limits
Things to watch out for
- Idempotency: cron jobs may run more than once, so make tasks safe to repeat.
- Retries: configure retries carefully to avoid duplicate side effects.
- Time zones/DST: use UTC unless you really need local time.
- Concurrency: prevent overlapping runs if a job takes longer than its interval.
- State: store progress in a DB or queue; don’t rely on in-memory state.
Example architectures
Simple periodic cleanup
Scheduler → Lambda/Function → delete expired records
More reliable job processing
Scheduler → Queue → Worker function(s) → DB updates
Long-running batch job
Scheduler → Workflow engine (Step Functions / Durable Functions) → multiple steps
Rule of thumb
- If the job finishes in a few seconds: direct scheduled function is fine.
- If it’s longer, needs retries, or has multiple steps: use a queue or workflow.
If you tell me your cloud provider or platform, I can show the exact setup and example config.