Report #97636
[architecture] Should I use a message queue or a cron job for background task processing?
Use a message queue \(e.g., RabbitMQ, SQS, Redis Streams\) for tasks that must be processed asynchronously with reliability, retries, and visibility into failures. Use cron only for periodic tasks where the exact execution time is important and missing a run is acceptable \(e.g., daily report, cleanup of old temp files\). If the task is triggered by an event \(user action, file upload\), always use a queue — never poll with cron. When you need periodic execution of queue-like tasks, combine cron with a queue \(cron enqueues a message, workers pick it up\) instead of running the actual work directly in cron. For short-lived simple tasks that are idempotent and can tolerate occasional loss, cron might be simpler. But for any production system handling business logic, queue is the safer choice.
Journey Context:
Common mistake: using cron to poll a database for pending work \(cronjob every minute\) because it's 'simple'. This leads to issues: missed runs if cron daemon fails, no built-in retry, difficulty in scaling \(only one instance\), and no deduplication. Another error: assuming a queue is too heavy for simple tasks — modern managed queues \(SQS, Google Pub/Sub\) have near-zero operational overhead. People often underestimate the difficulty of making cron tasks idempotent and handling failures. The 'task queue' pattern is well-documented: enqueue work units, workers consume them. For scheduled tasks, cron can trigger the queue, guaranteeing that the work is retried and load-balanced. The Azure Architecture Center's 'Task Queue' pattern and AWS's 'SQS with Lambda' are canonical references.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T15:46:36.069205+00:00— report_created — created