Queue Systems in PHP: From a Simple Cron Job to a Distributed Queue

Years ago, back in my agency days, the first complaint we got on an accounting integration we were running sounded innocent enough: "When I press the Issue Invoice button, the page spins for 20 seconds." We looked at the code; within the HTTP request, the button was generating a PDF, connecting to the e-invoice service, sending two emails and firing a webhook to the accounting software. All synchronous, all in the same request. On days the e-invoice service slowed down, requests hit the 30-second PHP limit, the user pressed the button again, and duplicate invoices were created. An average of 60 duplicate records a month, and the accounting team spent two days cleaning up. The diagnosis was simple: this project needed a queue. The really interesting question was — how much of a queue?

The hero everyone underestimates: cron and a database table

In the PHP world, whenever queues come up, minds immediately jump to RabbitMQ and Kafka. Let me be frank: in most of the projects I've delivered over the years, the first queue was nothing more than a MySQL table and a cron job running once a minute. A jobs table: job type, payload, status, attempt count, available-at time. Cron wakes up, processes the pending jobs in order, and it's done.

This architecture has virtues that don't deserve to be underestimated. Zero new infrastructure — it runs on the database and cron you already have. Jobs are queryable with SQL; the answer to "which jobs failed yesterday?" is a SELECT. Backups, monitoring, access control — all within your existing database practice. That's exactly what we did on that accounting project: the button now just writes the job to the table and says "your invoice is being prepared," and cron takes care of the rest. Button time dropped from 20 seconds to 300 milliseconds, and duplicate invoices went to zero.

At first, the invoice button did every task within the same HTTP request; later, it wrote the job to a table and left it to cron.
Without any new infrastructure, 20 seconds dropped to 300 milliseconds.

This layer has another overlooked advantage: scheduled jobs come for free. Saying "issue this invoice tomorrow morning at 09:00" just means writing a date into the available-at column. Deferred notifications, reminder emails, closing accounts whose trial period has ended — all the same table, the same worker. Without building separate scheduler infrastructure, you've combined the queue and the calendar into a single mechanism.

When the latency of a cron that wakes up once a minute becomes unacceptable, the next step is cheap, too: instead of cron, one or two worker processes running continuously under supervisor. Same table, same code, sub-second latency.

The moment the database queue hits the wall

So how far does this modest setup take you? I learned its limits firsthand, too. On a past e-commerce project, on campaign day, at a job volume approaching 4,000 per minute, the jobs table became the scene of lock contention: workers were trying to grab the same rows, and we were getting by with SELECT ... FOR UPDATE SKIP LOCKED, but as the table grew, the job-fetching query slowed down and we were competing for the same resources as the main application database. The queue's load had started slowing down the very application it was supposed to protect — an ambulance running over its own patient.

At that point we moved to a Redis-based queue. The beauty of this move in Laravel projects is that not a single line of the job classes changes; only the connection configuration does. With Horizon, real-time worker status, per-job duration distributions and per-queue load charts come out of the box. We went through the same campaign scenario the following month; 4,000 jobs a minute isn't even a warm-up lap for Redis.

As for RabbitMQ, we've only truly needed it on a handful of projects so far — and what they all had in common was the need to talk over the same queue with systems outside PHP (a warehouse management system written in Java, a telemetry collector written in Go). Setting up RabbitMQ on a single-language, single-application project is like buying a forklift for the corner store; the power is real, the need is imaginary.

Tiers of queue architecture: starting from cron and a database table, moving up to supervisor workers, Redis and Horizon, with RabbitMQ at the top.
Choosing the technology is the easiest twenty percent of queue work.

The truly hard part of queues: a protocol for facing failure

Choosing the technology is the easiest twenty percent of queue work. The hard part is designing what happens when jobs fail — because a queue means the error is detached from the user and becomes your responsibility. The user saw the "your invoice is being prepared" message and walked away; if the e-invoice service crashes at that moment, who is going to tell them, and how?

The minimum protocol I apply without exception in every queue-based system — and require in my current team as well — is this:

  • Every job is written to be idempotent: running it twice produces the same result as running it once. This is the precondition for retries; adding retries to a non-idempotent job is just automating the production of duplicate invoices.
  • Attempt limits and increasing backoff: 3 attempts, at 1-5-15 minute intervals. If the other service is down, there's no point hitting it 3 times in 10 seconds.
  • Dead-letter queue: a job that runs out of attempts isn't deleted; it lands in failed_jobs and shows up on someone's screen. An invisible dead-letter queue means invoices quietly disappearing.
  • Per-job timeout: no single hanging HTTP call is allowed to hold a worker hostage forever.

Every item on this list is the lesson of a concrete accident on a past project; I'll leave it to you to guess which accident goes with which item.

The minimum protocol for queue-based systems: idempotent jobs, retries with increasing backoff, a dead-letter queue and per-job timeouts.
A queue detaches the error from the user and makes it your responsibility.

Then there's the question of priority. A single queue means a password reset email stuck behind 50,000 marketing emails sent on campaign day — and a user expecting an email within two minutes won't forgive a forty-minute delay. That's why we split jobs into at least two classes: jobs the user is waiting on, and background load. Each class has its own queue and its own worker pool; no matter how high the marketing flood rises, the critical lane stays clear.

The 2026 touch: Horizon isn't the only one watching the queue anymore

A layer we added recently brought this architecture a kind of relief I didn't expect. We exposed our queue metrics to our operations agent via MCP; the agent regularly scans the jobs that land in failed_jobs, groups the error messages and posts diagnoses to Slack such as "in the last two hours, 34 jobs failed with the same SSL error; the other service's certificate changed last night." Sweeping the dead-letter queue used to be a Monday-morning chore; now we close most cases with the agent's diagnosis before users even notice. Code still makes the retry decisions, and humans still make the deletion decisions — the agent is only a lookout. But nothing explains the value of a good lookout as well as the years you spent without one.

The deploy side also needs queue-specific attention, and every new team learns this the hard way at least once: because workers are long-lived processes, they keep running the old code after you update it. You shipped the new version and fixed the buggy job class, but jobs are still failing — because the worker is running the class it loaded into memory three days ago. Gracefully restarting the workers on every deploy (letting them finish the job in hand) should be a non-negotiable step in the deploy script.

In short, my advice is modest: start your queue with cron and a table, move up a floor when you get stuck, and spend your energy on the failure protocol rather than on choosing technology. If some version of the "press the button and it spins for 20 seconds" story is playing out in your project, which floor you need usually becomes clear after half a day of discovery — and the answer, more often than you'd guess, is "a table and cron are enough." I'm always up for a chat about queues; the contact page is open.