Architecture · By Rivtor · Updated
Cron jobs vs queues vs background workers
Use a scheduler to decide when work should start, a queue to buffer and deliver work, and a worker to execute it. They solve different problems and are often combined. Choose the pattern from timing, retries, concurrency and acceptable data-loss behaviour.
See the Rivtor deployment workflow →
Separate time from execution
A scheduled trigger can enqueue a daily report, and a worker can execute it when capacity is available. The schedule determines timing; the queue records pending work; the worker supplies compute. Calling all three a cron job hides the failure boundary.
For a small one-off maintenance operation, a direct scheduled process may be sufficient. For customer work that needs retries, status and concurrency control, a queue often makes those responsibilities clearer. Neither pattern guarantees correctness without application-level design.
Compare the requirements
| Requirement | Pattern to evaluate |
|---|---|
| Run at a specific interval | Scheduler with explicit timezone |
| React to a user request | Enqueue after authorized request validation |
| Handle bursts | Queue plus bounded worker concurrency |
| Long-running work | Dedicated worker with observable status |
| Avoid overlapping runs | Durable coordination or idempotent job identity |
Define what happens when one scheduled run takes longer than the interval. Define behaviour after downtime too: skip missed runs, catch up or merge them deliberately. Accidental overlap can produce duplicate emails, exports or database updates.
Make the job retryable
Give each logical operation an identifier. Store durable status and design repeated execution so the final effect is not duplicated. Set bounded attempts and backoff, and keep failures visible for review. A process exiting successfully is insufficient when its external side effect was not completed.
Use a transactional outbox or another deliberate handoff design when a database change and enqueue must be coordinated. Otherwise a crash between them can leave data changed without a job, or a job without the expected data.
Verify platform support explicitly
Rivtor documents background worker services. That does not establish a built-in cron scheduler or every queue durability requirement. Check the current supported contract and retain an external scheduler or broker when needed.
Rehearse a normal run, overlap, worker interruption and an unavailable dependency with synthetic work. Check timezone and daylight-saving behaviour where relevant. Compare accepted job identities with outputs; an empty queue is only useful evidence if the intended results exist.