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

Here is a simple rule: if it takes more than 200 milliseconds, it should probably be a queue job. Sending emails, resizing images, generating PDFs, calling third-party APIs — all of these should happen in the background.

How queues work in Laravel

When you dispatch a job, Laravel serializes it and puts it in a queue (a Redis list, a database table, etc). A separate worker process picks it up and runs it. The web request returns immediately, and the user does not wait.

Creating a job

php artisan make:job SendWelcomeEmail
class SendWelcomeEmail implements ShouldQueue {
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(public User $user) {}

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

Dispatching jobs

// Dispatch immediately
SendWelcomeEmail::dispatch($user);

// Dispatch with delay
SendWelcomeEmail::dispatch($user)->delay(now()->addMinutes(5));

// Dispatch to a specific queue
SendWelcomeEmail::dispatch($user)->onQueue('emails');

Running the queue worker

php artisan queue:work
php artisan queue:work --queue=emails,default
php artisan queue:work --tries=3 --timeout=60

Handling failures

Jobs can fail. Configure retries and timeouts. Use the failed method to handle failures gracefully:

public function failed(Throwable $exception): void {
    // Notify admin, log error, etc.
    Log::error('Job failed', ['user' => $this->user->id, 'error' => $exception->getMessage()]);
}

Use Horizon

Laravel Horizon is a dashboard for monitoring your Redis queues. It shows throughput, wait times, job counts, and failures in real time. If you are using Redis queues in production, install Horizon.

Queues are one of those features that completely change how you build web applications. Once you start using them, you will find more and more things to push off the main thread.

LaravelBackend

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.