September 29, 2026 3 min read Laravel

Mastering Laravel Queue Workers: Redis Optimization, Supervisor Tuning & Failed Job Handling (Vol 5)

1. The Anatomy of High-Throughput Queue Processing in Laravel

Modern web applications rely heavily on asynchronous execution. Offloading long-running tasks such as transactional email dispatch, image transformations, PDF generation, and webhook delivery is critical to maintaining sub-200ms HTTP response times.

While Laravel provides seamless out-of-the-box support for database, Amazon SQS, and Beanstalkd drivers, Redis stands as the industry gold standard for low-latency, in-memory job handling.

Architectural Rule: Never execute synchronous external HTTP requests, file uploads, or complex reporting queries directly inside user-facing controller actions. Always push them to a dedicated Redis queue.

2. Optimizing Redis Queue Configuration

To eliminate contention between application cache and queue payloads, configure a dedicated Redis connection inside your config/database.php and config/queue.php files:

Snippet
// config/queue.php
'connections' => [
    'redis' => [
        'driver' => 'redis',
        'connection' => 'queue',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => 120,
        'block_for' => 5,
        'after_commit' => true,
    ],
],

The after_commit => true parameter guarantees that a job is only dispatched after the wrapping database transaction has successfully committed, preventing race conditions where a worker attempts to fetch a model before it exists on disk.

3. Production Supervisor Daemon Configuration

In production environments (such as Ubuntu, Debian, or AlmaLinux), queue workers must run as background daemons monitored by Supervisor. If a worker terminates due to memory exhaustion or deployment restarts, Supervisor will instantly relaunch it.

Snippet
# /etc/supervisor/conf.d/laravel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600 --memory=128
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=4
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/worker.log
stopwaitsecs=3600

4. Performance Metrics: Database vs Redis Drivers

Below is a comparative breakdown of queue processing throughput across different workload scales:

Queue Driver Latency (P95) Max Jobs / Sec (4 Cores) Memory Overhead Failure Recovery
Database (MySQL/MariaDB) 140ms 180 jobs/s High (Row Locks) Manual Table Query
Redis In-Memory 4ms 2,400+ jobs/s Ultra Low Automatic Dead-Letter Queue
Amazon SQS 45ms 1,100 jobs/s Network Bound AWS CloudWatch / SQS DLQ

5. Graceful Deployment & Zero-Downtime Worker Restarts

Whenever new code is deployed to production, running workers hold previous class definitions in PHP process memory. Always trigger a graceful restart during your CI/CD deployment pipeline:

Snippet
# Trigger graceful reload inside deployment script
php artisan queue:restart

This signals active workers to finish their current job before exiting, allowing Supervisor to spawn new processes loaded with the latest application code.

Frequently Asked Questions

Quick, authoritative answers to common questions on this topic

Q1 Why should I use Redis over database queues in production Laravel apps?
Redis operates completely in-memory, delivering sub-millisecond atomic popping and pushing operations. Database queues create write amplification, table locks, and row contention during high traffic spikes.
Q2 How do I prevent memory leaks in long-running Laravel queue workers?
Run queue workers with strict memory limits using the --memory=128 flag, set max-jobs=1000, and ensure all Eloquent queries inside jobs run with chunking or lazy collections to avoid circular references.
Q3 What is the recommended Supervisor configuration for Laravel workers?
Configure Supervisor with autostart=true, autorestart=true, stopasgroup=true, and appropriate numprocs based on server CPU cores to guarantee uninterrupted daemon execution.
Aditya Kumar

Aditya Kumar

Full-Stack Engineer

Chat on WhatsApp