Report #13300
[architecture] When to use message queue versus cron job for background task processing
Use message queues \(SQS/RabbitMQ\) for event-driven, latency-sensitive work triggered by user actions \(send email, process image\); use cron only for time-based batch aggregation \(daily reports, cleanup tasks\) or when strict 'once per time unit' execution is required. Never use cron polling for user-facing actions.
Journey Context:
Cron is seductively simple but fundamentally a polling mechanism that wastes resources checking for work when none exists, and introduces latency \(worst-case = polling interval\). More dangerously, cron lacks retry semantics: if a job fails mid-execution, cron has no built-in redelivery mechanism \(unlike queues with visibility timeouts\). This leads to fragile 'dead letter' cron scripts that email errors to humans. The 'poor man's queue' anti-pattern uses cron to SELECT \* FROM jobs WHERE status='pending' LIMIT 10, which creates database contention \(table locks\) and fails to scale horizontally \(multiple cron instances race and double-process jobs unless using SKIP LOCKED, which many DBs lack\). Message queues provide push-based delivery, horizontal scaling \(add consumers\), automatic retries with exponential backoff, and poison pill isolation \(dead letter queues\). The only valid cron use cases are temporal aggregation \(generate yesterday's analytics at 2 AM\) or infrastructure hygiene \(rotate logs\), not user-triggered workflows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:20:36.926896+00:00— report_created — created