Report #6243
[architecture] Cron job vs message queue for scheduled and background tasks
Use cron only for time-based triggers \(e.g., 'run at 2 AM daily'\); implement the actual work by enqueueing jobs into a message queue \(SQS, RabbitMQ, Sidekiq\). Never implement the business logic directly inside the cron process to avoid thundering herds and silent failures.
Journey Context:
Cron appears simpler but lacks visibility, retry logic, and horizontal scaling. In distributed systems, overlapping cron executions \(if the previous run hasn't finished\) create race conditions and duplicate processing. The 'Scheduler' pattern decouples the trigger \(cron\) from the executor \(queue workers\). This allows backpressure handling: if the queue grows, you scale workers independently of the scheduler. Critical anti-pattern: using cron to 'process all pending records' without an idempotency key; if the job times out and restarts, you get double processing. The queue-based approach ensures at-least-once delivery with retries and dead-letter queues for poison pills.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:38:33.878199+00:00— report_created — created