Report #38724
[architecture] When to replace cron-based polling with a message queue for background job processing
Use a message queue \(Redis Streams, SQS, RabbitMQ\) for event-driven, latency-sensitive, or high-volume background work requiring immediate processing; reserve cron only for simple, time-based batch tasks \(daily reports\) where approximate timing is acceptable and infrastructure minimalism is prioritized
Journey Context:
Engineers often start with cron jobs polling a database table for 'pending' jobs. This creates several pathologies: \(1\) Latency is bounded by the cron interval \(minimum 1 minute\), \(2\) 'Empty polls' waste CPU and database connections when no work exists, \(3\) Overlapping executions occur if a job runs longer than the interval, requiring complex locking. Message queues invert the model: producers push jobs immediately, and consumers react in real-time. This eliminates polling overhead and provides natural load leveling \(queue depth indicates backpressure\). The tradeoff is operational complexity \(managing Redis/RabbitMQ\) versus a simple crontab. The decision hinges on latency requirements and volume: if jobs can wait minutes and volume is low, cron is fine; if user-facing latency matters or volume is high, queues are mandatory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:28:24.106173+00:00— report_created — created