Skip to content

Expert Answers to Your Magento, Shopify & Shopware Questions

Vendor-neutral, engineer-written explanations. Clear definitions first, then practical steps with real examples — no fluff.

Stagebit builds and maintains stores on Magento, Adobe Commerce, Shopify, Shopware, and Laravel, and this library holds the questions our own engineers get asked most often on each platform.

How do queues work in Laravel and when should I use them?

SB
Written by Stagebit Engineering Team
Updated November 2026 8 min read Verified by engineers

Laravel queues let your application answer a request right away and finish the slow part afterward. Your code dispatches a job, a queue connection holds it, and a worker process runs it in the background. Use a queue when the visitor does not need the result before the page loads. Skip it when they do.

Quick answer

A Laravel queue stores jobs in a backend such as a database, Redis, Amazon SQS, or Beanstalkd. A worker started with php artisan queue:work takes each job and runs its handle method outside the web request. The sync driver is the exception, because it runs jobs immediately in the current process. Queues suit slow, retryable work such as email, API calls, and file imports.

How do Laravel queues work?

A queue splits one slow task into two steps. First you put a job on a list, then a worker runs it later as a background job. The Laravel queue documentation lists the built-in drivers as database, Amazon SQS, Redis, and Beanstalkd. The synchronous driver is different. It runs each job immediately in the current process, which suits development and testing.

  1. Dispatch. A user action, such as placing an order, makes your code call SendOrderConfirmation::dispatch($order). The job class implements ShouldQueue, so Laravel serializes it onto the configured connection.
  2. Store. The driver holds the job payload. Laravel stores only the identifier of an Eloquent model you pass to a job. It reloads the model when the job runs.
  3. Run. A worker pulls the next job and calls its handle method. The worker is a long-running PHP process, separate from your web server.
  4. Finish or retry. A successful job leaves the queue. A job that throws an exception returns to the queue. After its last allowed attempt, it lands in the failed jobs table.
Laravel queues flow: the app dispatches a job, the queue stores it, a worker runs it, and failures retry then go to failed_jobs.

Laravel separates connections from queues. A connection is the backend, such as database, Redis, or Amazon SQS. A queue is a named list on that connection, such as default or high. Jobs go to the connection’s default queue unless you name another one.

How do you create and run a queued job in Laravel?

An order confirmation email is a typical first job. The customer should not wait for the mail server before they see the order page.

1. Create the job

Generate the class with Artisan. Laravel places it in the app/Jobs directory.

php artisan make:job SendOrderConfirmation

2. Define what the job does

The generated class implements ShouldQueue. That interface tells Laravel to push the job onto a queue instead of running it immediately. The handle() method holds the work.

<?php

namespace App\Jobs;

use App\Mail\OrderConfirmationMail;
use App\Models\Order;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Mail;

class SendOrderConfirmation implements ShouldQueue
{
    use Queueable;

    public function __construct(public Order $order) {}

    public function handle(): void
    {
        Mail::to($this->order->customer_email)
            ->send(new OrderConfirmationMail($this->order));
    }
}

In this example, Order, OrderConfirmationMail, and the customer_email column belong to your own application. Laravel does not provide them.

3. Dispatch the job

Dispatch the job after the order saves successfully.

use App\Jobs\SendOrderConfirmation;

SendOrderConfirmation::dispatch($order);

The controller returns immediately when the connection is asynchronous. The sync driver runs the job inside the request instead.

If you create the order inside a database transaction, add afterCommit(). Laravel then waits for the commit before it dispatches the job. Without it, a worker can pick up the job before the order exists in the database. If the transaction rolls back, Laravel discards the job.

use App\Jobs\SendOrderConfirmation;
use App\Models\Order;
use Illuminate\Support\Facades\DB;

// $validated holds your validated order data
DB::transaction(function () use ($validated) {
    $order = Order::create($validated);

    SendOrderConfirmation::dispatch($order)->afterCommit();
});

4. Start a worker

New Laravel applications already use the database connection and include the jobs table migration. Start a worker with this command.

php artisan queue:work

To use another driver, change QUEUE_CONNECTION in your .env file. If your project has no jobs table, run php artisan make:queue-table and then php artisan migrate.

Run the worker in a spare terminal while you develop. In production, keep it alive with a process manager such as Supervisor.

When should you use a queue in Laravel?

Use a queue when the work is slow, needs retries, or does not change what the visitor sees next. The Laravel documentation cites parsing an uploaded CSV file as a task too slow for a normal web request.

  • Sending email and notifications after an order, signup, or password reset.
  • Calling third-party APIs such as payment, shipping, or CRM services, where the remote system can be slow or down.
  • Importing or exporting large files, processing uploaded images or video, and generating PDFs or reports.
  • Updating a search index after a record changes.
  • Splitting a bulk update of thousands of records into smaller background jobs.
  • Recurring tasks, such as reminders or data syncs, that the scheduler dispatches as queued jobs.

When a queue is the wrong choice

Do not queue work the visitor needs in the response, such as form validation or a cart total. If the page must show the result, run the task inside the request.

A queue also adds a worker process, a failure path, and monitoring to your stack. For a task that finishes in milliseconds, that overhead usually outweighs the benefit. A queue only runs while a worker is alive.

Which Laravel queue driver should you use?

The right driver depends on your workload, your existing infrastructure, and how much you want to operate yourself. The database driver is the default in new Laravel applications. It can serve an application while job volume stays modest. Laravel provides one queue API across backends, so switching drivers generally does not require rewriting job classes. Driver-specific features, such as SQS FIFO groups, are the exception.

DriverBest forTrade-off
DatabaseApplications with a few job types and modest volume. It is the default in new Laravel applicationsWorkers poll the jobs table, so heavy queue traffic adds load to that database
RedisBusier queues, plus Laravel Horizon, a dashboard built for Redis queuesYou run and maintain a Redis server
Amazon SQSTeams already on AWS that want a managed queue with no queue server to runA delayed job can wait at most 15 minutes, and message payloads have a size limit
SyncLocal development and tests, where jobs run immediatelyJobs run inside the web request, so you get no background benefit

On Amazon SQS, three time limits are easy to confuse. The message delay is how long a job waits before a worker can take it, up to 15 minutes. The visibility timeout, set in the AWS console, decides when SQS retries a job still in progress. The worker timeout is the longest a worker lets a job run, 60 seconds by default. Only the delay has the 15-minute cap, so it never limits how long a job can run.

  • A new application sends order emails and runs one nightly import. The database driver is enough.
  • A team wants a dashboard for queue activity and failed jobs. Redis with Horizon fits.
  • An application already runs on AWS, and nobody wants to operate a queue server. Amazon SQS fits.

If you do change drivers, jobs already stored on the old connection stay there. Keep a worker running on that connection until it is empty before you retire it. If you want a second opinion on a queue design, our Laravel development team can review it.

How does Laravel handle failed queued jobs?

Laravel attempts a job only once by default. Each time a worker picks up a job, that counts as one attempt. An exception, a timeout, or a release back onto the queue uses up an attempt. After the last allowed attempt, Laravel inserts the job into the failed_jobs table.

New applications typically include the migration for that table. If yours does not, run php artisan make:queue-failed-table and then migrate. Jobs that run synchronously never land in this table.

To allow more attempts, set the limit and a retry delay on the worker.

php artisan queue:work --tries=3 --backoff=3

That command allows three attempts and waits three seconds between them. Without --backoff, Laravel releases a failed job back onto the queue immediately. You can also set these values per job with the Tries and Backoff attributes. A backoff array gives escalating delays.

Laravel does not undo partly finished work when a job fails. If you need an alert or cleanup, define a failed() method on the job and write that logic yourself. Laravel creates a fresh instance of the job before it calls failed(). Any property changes made during handle() are lost.

To review failures and retry them, use these commands.

php artisan queue:failed
php artisan queue:retry all

Fix the cause first. Retrying everything before that only recreates the same failures. Check the table regularly so failures do not pile up unnoticed.

A retried job can run more than once, so important operations must be safe to repeat. Suppose a timeout hits after a job sends the confirmation email. The next attempt would send a second email unless the job checks first. The same applies to creating an invoice or charging a payment.

ShouldBeUnique solves a different problem. Laravel locks the job when it dispatches it, and it dispatches no other copy until the lock clears. It releases the lock when the job finishes or fails all its attempts. It does not guarantee the job runs only once, so it never replaces jobs that are safe to repeat. Unique jobs need a cache driver that supports locks.

What can go wrong with Laravel queues in production?

Check these before you rely on a queue

  • Stale code after deploys: Workers keep the booted application in memory, so run php artisan queue:restart in every deploy script. Workers finish their current job before they exit, and the restart signal needs a configured cache driver. Horizon users run php artisan horizon:terminate instead.
  • Timeout and retry_after: The default worker timeout is 60 seconds. Keep it at least several seconds shorter than the connection’s retry_after value, or a job can run twice. On Amazon SQS, the visibility timeout takes the place of retry_after.
  • Urgent jobs stuck behind slow ones: Dispatch urgent work with onQueue('high'). Then start the worker with php artisan queue:work --queue=high,default so it clears the high queue first.
  • Workers that stop or grow: A worker exits after a timeout or a restart, and long-running workers can accumulate memory. Run queue:work under a process monitor such as Supervisor. Options such as --max-time and --memory make a worker exit cleanly so the monitor restarts it.

Where should you start with Laravel queues?

Start with one job that clearly does not belong in the request, such as a confirmation email. Run it on the connection your application already uses. Keep a worker running under a process monitor. Restart workers on every deploy, and set tries and backoff deliberately.

Write every job so it is safe to repeat. Retries and timeouts can run the same job more than once. Move to Redis or Amazon SQS only when your workload or infrastructure calls for it.

Was this answer helpful?

Your feedback helps us improve our answers.

Still need help?

Questions about queues in your Laravel app?

If you're weighing which queue driver or retry setup fits your workload, we're happy to walk through what you're running and what your options are.

Talk to Laravel Experts