Drupal Queue Workers: Diagnose a Backlog Before Adding More Cron Runs

A Drupal queue is meant to move slow work out of a page request. When a backlog grows, running cron more often is an understandable first reaction, but it may simply repeat the same failing worker or overload a slow external service. Start by finding which queue is growing, what code processes it, and whether each item succeeds, retries or remains claimed.

Editorial illustration: Drupal queue items flow from a producer through a worker, with failed items diverted to a review lane

Editorial illustration; queue behavior depends on the implementation and worker.

Summary

  • Use Drupal’s Queue API for long-running or failure-prone work that should not hold a web request open.
  • A growing backlog can mean missing cron, slow work, repeated exceptions or a dependency that is unavailable.
  • Measure the producer and worker separately before increasing concurrency or changing queue storage.

Why Drupal has queues

Drupal’s API guidance recommends queues for work likely to take a long time or time out, such as remote data retrieval, email delivery and intensive file tasks. Short, inexpensive periodic actions can run directly during cron. A queue item stores the data needed for later processing; a QueueWorker plugin handles one item when Drupal runs cron or another supported worker process.

This separation improves request reliability, but it does not make a job automatically successful. The worker must be safe to retry, and the site needs a process that actually consumes the queue. A queue can grow while the site continues to serve pages normally, so treat queue health as an operational signal rather than assuming a working homepage means the background work is fine.

Trace the queue end to end

  1. Find the producer. Identify the module, event or form submission that creates queue items. Confirm whether it enqueues once or can enqueue duplicates after a retry.
  2. Name the queue and worker. Search custom code and enabled modules for the queue name and the corresponding QueueWorker plugin ID. Read the worker annotation/attribute for its cron time limit and queue association.
  3. Confirm a runner exists. Check Drupal cron status and the host’s scheduled job or deployment-specific runner. A configured cron URL or Drush schedule that never executes is not a consumer.
  4. Inspect logs around processing. Look for exceptions, timeouts, authentication errors and remote API responses. Drupal’s queue worker can leave an item for later processing after an exception; repeated failure may keep the same work visible.
  5. Compare arrival and completion. Record queue size at two times and the number of successful items processed. If production adds 100 items each hour and the worker clears only 40, more frequent cron may not close the gap unless each run has capacity and the dependency is healthy.

The exact inspection command depends on the storage backend and installed modules. Drush commands such as queue:list and queue-specific processing commands are available only when the relevant Drush integration is installed; verify the command with drush list on your project before using it. Do not assume core exposes one universal command to safely inspect or delete every queue.

Read failure behavior before retrying

Queue worker exceptions matter. Drupal documents RequeueException for work that is not finished but can be made available again, and SuspendQueueException when a problem affects the remaining items in that queue for the current run. An ordinary exception is logged and can leave an item to be retried later. The right exception depends on whether the failure is item-specific or system-wide.

For example, a malformed payload may fail repeatedly while later items are healthy. A remote API outage may make every item fail and should pause further attempts during that run. A worker that sends an email must also avoid sending it twice if the process crashes after the remote service accepts the message but before Drupal records completion. Use an idempotency key or a state check when the external system supports it.

Improve throughput carefully

If the worker is healthy but simply too slow, estimate service time per item and the arrival rate. First remove unnecessary per-item calls, batch work where the remote API permits it, and set a clear timeout. Then schedule cron at an interval that fits the host’s limits. A separate queue runner or managed worker can make sense for sustained high volume, but review its maintenance status, security coverage, storage support and overlap behavior.

Increasing parallel workers can help independent tasks, but it may also race on the same entity or exceed an external API’s rate limit. Confirm the queue backend’s locking and claim semantics, and test parallel processing against duplicate execution. Add metrics for queue length, oldest-item age, success count and failure count so operators can tell whether a deployment improved the situation.

For a deployment, make sure the queue backend and worker configuration are the same in staging and production where intended. Avoid deleting a queue to “clear the warning” before understanding whether it contains mail, files or business-critical synchronization. If stale items must be discarded, export or log a sample, agree on the consequence with the owner, and use a queue-aware method with a rollback plan.

Common mistakes

  • Running cron repeatedly without checking the worker’s error log.
  • Treating a queue as a durable job broker without verifying backend guarantees.
  • Retrying non-idempotent tasks that can send duplicate messages or create duplicate records.
  • Increasing concurrency without checking API limits and entity-level race conditions.
  • Deleting queued work before identifying what the payload represents.

If cron itself is unreliable, first check Drupal’s core update and cron operations. For remote API calls, compare the queued job’s request with a Drupal JSON:API endpoint design so timeouts and access behavior are understood.

My Take

Queue size by itself is not enough to diagnose a system. The most useful alert is often the age of the oldest item alongside success and failure counts. That tells the team whether work is merely waiting its turn or stuck behind one broken dependency.

Bottom Line

Trace producers, workers and the runner separately. Fix repeated failure or capacity imbalance before increasing cron frequency, and make retry behavior safe for the side effects your job performs.

Sources