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:
// 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.
# /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=36004. 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:
# Trigger graceful reload inside deployment script
php artisan queue:restartThis signals active workers to finish their current job before exiting, allowing Supervisor to spawn new processes loaded with the latest application code.