Prompt
How do I add delayed jobs and scheduled tasks to my app?
Latest observation
Oct 22, 2026
OpenAI APIWeb search: off
There are a few common ways to add delayed jobs and scheduled tasks to an app, and the right choice depends on your stack and how reliable you need it to be.
1) Pick the right concept
- Delayed job: run something once in the future, e.g. “send this email in 10 minutes.”
- Scheduled task / recurring job: run on a schedule, e.g. “clean up expired sessions every hour.”
2) Typical approaches
A. Use a background job queue
Best for most apps.
Examples:
- Node.js: BullMQ, Agenda, Bree
- Python: Celery, RQ, Dramatiq
- Ruby: Sidekiq, Solid Queue
- Java/Kotlin: Quartz, Spring Scheduler, Hangfire-like equivalents
- .NET: Hangfire, Quartz.NET
How it works:
- Your app enqueues a job with a delay or schedule.
- A worker process picks it up later.
- The worker executes the task outside the web request.
Benefits:
- Reliable
- Retries
- Monitoring
- Doesn’t block your app
B. Use a scheduler/cron
Best for simple recurring tasks.
Examples:
- Linux
cron - Kubernetes CronJob
- Cloud schedulers:
- AWS EventBridge / CloudWatch Events
- GCP Cloud Scheduler
- Azure Timer Trigger / Logic Apps
Use this for:
- nightly reports
- cleanup tasks
- syncing data periodically
C. Use your framework’s built-in scheduler
Some frameworks include scheduling support:
- Django + Celery / django-crontab
- Rails + Active Job + Solid Queue/Sidekiq + cron
- Laravel Scheduler
- NestJS + Bull/BullMQ + cron decorators or scheduler modules
- ASP.NET hosted services / Hangfire
3) Recommended architecture
For anything beyond trivial:
- Web app enqueues jobs
- Queue backend stores job state
- Worker(s) process jobs
- Scheduler adds recurring jobs if needed
- DB holds domain data and maybe job metadata
A common setup:
- Redis or database as queue backend
- Separate worker container/process
- Separate scheduler process if recurring tasks are needed
4) Key design considerations
Reliability
- Persist jobs in a durable store
- Use retries with backoff
- Make jobs idempotent so running twice doesn’t break things
Time zones
- Store schedules in UTC unless business rules require local time
- Be careful with daylight saving time
Concurrency
- Prevent duplicate execution for the same scheduled task
- Lock or deduplicate jobs where necessary
Failure handling
- Dead-letter queue or failed-job table
- Alerts/logging for repeated failures
Long-running work
- Offload to workers, not request threads
5) Example patterns
Delayed job
“Send welcome email 15 minutes after signup”
Pseudo-flow:
- User signs up
- App enqueues
send_welcome_email(user_id)withdelay = 15m - Worker runs it later
Scheduled task
“Generate daily invoice summaries at 2 AM”
Pseudo-flow:
- Scheduler triggers every day at 2 AM
- It enqueues
generate_invoice_summaries(date) - Worker processes jobs
6) If you want a practical recommendation
If you tell me your stack, I can suggest the best tool and show setup code.
For example:
- Node.js + Redis → BullMQ
- Python + Django/FastAPI → Celery
- Ruby on Rails → Sidekiq
- .NET → Hangfire
- Java/Spring → Quartz or Spring Scheduler
If you want, I can give you:
- a minimal implementation for your framework,
- a production-ready architecture, or
- a comparison of job libraries for your stack.