Laravel & Backend7 min read

Laravel Queue and Job Processing for High Performance Applications

Md Shahed Alam
Md Shahed Alam
March 28, 2025
Laravel Queue and Job Processing for High Performance Applications

Picture this. A user signs up on your app. Your code sends a welcome email. The email service takes 2 seconds to respond. The user stares at a loading spinner for 2 seconds before seeing the success page.

That is a terrible experience. And it is completely unnecessary.

Queues let you say: "Do this later, in the background. The user does not need to wait." The user sees the success page instantly. The email gets sent a second later. Everyone is happy.

How queues work

When you push a job to a queue, you are basically leaving a note that says "please do this task." A separate process — the queue worker — picks up that note and does the work. The web request that created the note is already done and the user has their response.

Setting up

For development, the sync driver runs jobs immediately (no worker needed). For production, use Redis:

text
QUEUE_CONNECTION=redis

Creating a job

bash
php artisan make:job SendWelcomeEmail
php
class SendWelcomeEmail implements ShouldQueue {
    public function __construct(private User $user) {}

    public function handle(): void {
        Mail::to($this->user)->send(new WelcomeMail($this->user));
    }
}

Dispatching it

php
// In your controller, after creating the user
SendWelcomeEmail::dispatch($user);

// Want to delay it? Easy.
SendWelcomeEmail::dispatch($user)->delay(now()->addMinutes(5));

That is it. The controller returns immediately. The job runs in the background.

Running the worker

bash
php artisan queue:work redis

In production, use Supervisor to keep the worker running even if it crashes:

ini
[program:laravel-worker]
command=php /var/www/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true

What happens when a job fails?

Jobs can fail — the email service might be down, the API might time out. Set a retry count:

php
public int $tries = 3;
public int $backoff = 60; // wait 60 seconds between retries

Failed jobs land in the failed_jobs table. You can inspect them and retry:

bash
php artisan queue:retry all

What else should go in a queue?

Anything that takes more than half a second and does not need to happen before the user gets a response:

  • Sending emails and SMS
  • Processing uploaded images or videos
  • Generating PDF reports
  • Calling external APIs
  • Sending webhooks
  • Syncing data to third-party services

Once you start using queues, you will find yourself reaching for them constantly. They are one of the best tools in Laravel.

LaravelQueuesJobsPerformance

Ready to build something great?

Let's talk about your project. We will give you honest advice, a clear plan, and a fair price. No pressure, no sales pitch.

Free consultation
No commitment required
Response within 24 hours