Report #95734
[architecture] Choosing between message queues and cron jobs for background processing
Use message queues \(SQS, RabbitMQ, Redis Streams\) when work is event-driven \(user signup → send email\), requires immediate processing \(<1s latency\), needs horizontal scaling of workers, or must guarantee at-least-once delivery with dead-letter queues. Use cron only for: time-based aggregation \(daily reports\), cleanup/maintenance \(log rotation\), or when work is not event-driven and >1 minute precision is acceptable
Journey Context:
The 'polling anti-pattern': developers cron 'process\_unsent\_emails every minute' which creates 59s average latency, wastes CPU checking empty queues, and creates race conditions if job duration > interval \(overlapping runs\). Queues provide push-based immediate processing, visibility timeout \(lease mechanism\) for safe retry without double-processing, and natural backpressure \(queue depth metrics\). Cron is stateless: if it fails mid-run, it doesn't know which items were processed on restart \(requires idempotency tracking separately\). Hybrid pattern: cron enqueues batch work \('check all expired subscriptions'\) which fans out to queue items for individual processing. Kubernetes CronJob vs Deployment of queue workers illustrates the operational split.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:16:21.139393+00:00— report_created — created