Laravel 12 Horizon is a Redis/Valkey-backed queue supervisor and telemetry dashboard engineered to auto-scale worker processes across prioritized queues, whereas the Laravel database queue driver polls a relational jobs table using row-level SELECT ... FOR UPDATE SKIP LOCKED queries.
Quick Answer: On a 4-vCPU / 8GB ap-south-1 server, Laravel 12 Horizon backed by Valkey 8 processes 1,420 jobs/sec at 11ms P95 dispatch latency, whereas the database queue driver caps out at 145 jobs/sec and triggers MySQL InnoDB lock contention once concurrent workers exceed 12 processes.
Key Architecture Takeaways
- Relational Polling Tax: Every idle
databasequeue worker executes aSELECT+UPDATEcycle every few seconds, stealing IOPS from live checkout and API queries. - Horizon Auto-Scaling:
balance => 'auto'dynamically shifts PHP worker processes from low-priority email queues to high-priority webhook or invoice queues during traffic spikes. - Memory Leak Protection: Horizon's
memoryandmaxTimethresholds recycle long-running PHP processes before eloquent model caching bloats RAM. - Zero-Downtime Deploys: Running
php artisan horizon:terminatelets in-flight jobs finish cleanly before Supervisor boots fresh code.
flowchart LR
A[Laravel 12 Controller / Event] --> B{Queue Driver}
B -->|Valkey 8 + Horizon| C[Supervisor Auto-Balancer]
C --> D[High Queue: Webhooks / UPI]
C --> E[Default Queue: PDFs / AI]
B -->|Database Driver| F[MySQL jobs Table Polling]
F --> G[InnoDB Row Locks & IOPS Spike]
Why the Laravel Database Queue Stalled Our Client's GST & Webhook Pipeline
The database queue driver is Laravel's default in fresh installs, and it is great for getting started in 30 seconds. I have seen dozens of Indian SaaS teams leave QUEUE_CONNECTION=database running in productionโright up until their first festive sale or bulk cron run.
War Story 1 โ The InnoDB Deadlock Storm at 10:00 AM:
A B2B invoicing client in Rajkot ran 18 queue:work database processes under Supervisor to generate GST PDFs and send WhatsApp notifications. Every morning at 10:00 AM when 40,000 scheduled jobs hit the jobs table, MySQL CPU pinned at 98% and live user logins threw Lock wait timeout exceeded errors because workers were contending on jobs indexes. Migrating to Laravel 12 Horizon + Valkey 8 dropped MySQL CPU from 98% to 14% within 20 minutes.
War Story 2 โ Silent OOM Kills on Bulk Export Workers:
In my Junagadh lab, I tested a Laravel 12 Horizon worker processing 50,000 Eloquent records without chunkById() or DB::disableQueryLog(). Even with Horizon, PHP memory climbed to 1.4GB per worker until Linux OOM-killer terminated the process mid-job. Pairing Horizon's --max-jobs=500 worker recycling with strict chunkById(250) kept RSS memory flat at 68MB per worker.
Production Laravel 12 Horizon Configuration & Supervisor Unit
Below is the exact config/horizon.php auto-balancing setup and Supervisor unit I deploy for high-throughput Laravel 12 + Valkey 8 workloads.
config/horizon.php โ Priority-Balanced Production Pools
<?php
return [
'domain' => env('HORIZON_DOMAIN'),
'path' => env('HORIZON_PATH', 'horizon'),
'use' => 'default',
'prefix' => env('HORIZON_PREFIX', 'horizon:'),
'middleware' => ['web', 'auth'],
'waits' => [
'redis:high' => 15,
'redis:default' => 60,
],
'trim' => [
'recent' => 60,
'pending' => 60,
'completed' => 60,
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
],
'environments' => [
'production' => [
'supervisor-critical' => [
'connection' => 'redis',
'queue' => ['high', 'webhooks'],
'balance' => 'auto',
'autoScalingStrategy' => 'time',
'minProcesses' => 2,
'maxProcesses' => 12,
'balanceMaxShift' => 2,
'balanceCooldown' => 3,
'maxTime' => 3600,
'maxJobs' => 500,
'memory' => 128,
'tries' => 3,
'backoff' => [10, 30, 90],
'timeout' => 60,
],
'supervisor-bulk' => [
'connection' => 'redis',
'queue' => ['default', 'exports'],
'balance' => 'simple',
'processes' => 4,
'maxJobs' => 250,
'memory' => 256,
'tries' => 2,
'timeout' => 180,
],
],
],
];
app/Jobs/DispatchGstInvoiceJob.php โ Idempotent Horizon Job Contract
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class DispatchGstInvoiceJob implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $timeout = 45;
public int $uniqueFor = 3600;
public function __construct(public readonly string $invoiceUuid)
{
$this->onQueue('high');
}
public function uniqueId(): string
{
return $this->invoiceUuid;
}
public function handle(): void
{
// Render PDF and dispatch webhook safely without duplicate execution
}
}
/etc/supervisor/conf.d/laravel-horizon.conf โ Process Manager Config
[program:laravel-horizon]
process_name=%(program_name)s
command=php /var/www/app/artisan horizon
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
stdout_logfile=/var/www/app/storage/logs/horizon.log
stopwaitsecs=3600
Laravel 12 Queue Benchmark: Horizon (Valkey 8) vs Database Driver
Tested on a 4-vCPU / 8GB RAM Ubuntu 24.04 node running PHP 8.4, Laravel 12, MySQL 8.4, and Valkey 8.0 with 50,000 lightweight notification jobs.
| Benchmark Metric | Database Driver (8 Workers) | Database Driver (16 Workers) | Horizon + Valkey 8 (12 Auto Workers) |
|---|---|---|---|
| Sustained Throughput | 112 jobs/sec | 145 jobs/sec | 1,420 jobs/sec |
| P95 Dispatch-to-Start | 190 ms | 410 ms | 11 ms |
| MySQL CPU Utilization | 46% | 89% (Lock Contention) | 4% (Business Queries Only) |
| Worker RAM Footprint | 64 MB/worker | 66 MB/worker | 72 MB/worker |
| Zero-Downtime Grace Stop | Manual queue:restart |
Manual queue:restart |
Native horizon:terminate |
Horizon Operations & Migration Runbook (Database to Valkey)
When migrating an active Laravel 12 app from database queues to Horizon without dropping in-flight jobs:
- Drain Existing
jobsTable Safely: Do not flip.envQUEUE_CONNECTION=redisand kill database workers immediately. Leave two legacyqueue:work database --stop-when-emptyprocesses running for 15 minutes untilSELECT COUNT(*) FROM jobshits zero. - Enforce
retry_after > timeout: Inconfig/queue.php, always set'retry_after' => 240higher than Horizon's longest'timeout' => 180; otherwise Horizon will re-dispatch a long PDF/AI job while the first worker is still executing it. - Protect Horizon Dashboard Route: Gate
/horizonbehindHorizon::auth()checking your admin email or role inAppServiceProvider, never relying on IP allowlists alone. - Alert on
WaitTimeExceeded: Subscribe to Horizon'sLongWaitDetectedevent and push alerts to Slack or Telegram whenever thehighqueue wait exceeds 15 seconds.
When NOT to Use Laravel Horizon
- Low-Volume Sites Under 2,000 Jobs/Day: If you send 500 password resets and 200 invoices daily, the
databasequeue driver saves you from operating and monitoring a Redis/Valkey service. - Shared cPanel Hosting Without Supervisor: Horizon requires a persistent daemon (
php artisan horizon) andpcntlPHP extensions; on shared hosting without SSH/Supervisor, use database queues triggered by a cronqueue:work --stop-when-empty. - Single-Run 20-Minute Video Transcoding: Long-running CPU-bound media pipelines belong in dedicated Go/Python worker containers or AWS Batch rather than PHP Horizon workers.
โก Implementation Resources & Commercial Architecture:
Pair Laravel background workers with deterministic webhook retries and queue audits using n8n Production Hardening Pack (โน2,499 โ retry queues, dead-letter replay & JS/API safety checks) or grab all 4 core kits in The AI Systems Master Bundle. Test your Horizon log-parsing patterns instantly with our free Regex Tester. Need a high-throughput Laravel 12 + AI backend built (โน3Lโโน25L)? Schedule a call at Deepak Bagada Systems Advisory.
Authoritative Primary Sources & Research Citations
- Laravel 12 Official Horizon Documentation
- Laravel 12 Queues &
retry_afterConfiguration - Valkey 8.0 High-Throughput Persistence Guide
Related Engineering Guides
- Laravel 12 Octane FrankenPHP 2026 RPS Benchmark
- Laravel 12 GST Invoice Engine with chunkById
- Valkey 8 vs Redis 7 Throughput & P99 Latency 2026
- Free Regex Tester Developer Tool
Frequently Asked Questions
Does Laravel 12 Horizon work with Valkey 8 instead of Redis?
Yes. Valkey 8 is wire-protocol compatible with phpredis and predis. Point Laravel's redis connection in config/database.php at your Valkey 8 host and Horizon runs with zero code changes.
Why does the database queue driver slow down MySQL under load?
Each worker polls the jobs table and acquires row-level locks via SELECT ... FOR UPDATE SKIP LOCKED. Above 10โ12 concurrent workers, polling overhead and index contention degrade response times for live web requests.
What happens if retry_after is shorter than Horizon's timeout?
Laravel assumes the worker crashed and re-releases the job to a second worker while the first worker is still running, causing duplicate emails, double-billed webhooks, or corrupted exports. Always keep retry_after at least 30โ60 seconds higher than timeout.
How much RAM does Laravel Horizon need in production?
Expect 65โ80MB RSS per idle/lightweight PHP worker plus ~40MB for the Horizon master process. A pool of 10 workers comfortably fits inside a 2GBโ4GB worker budget with memory => 128 caps.
Bottom Line
Leave the database queue driver for prototypes and low-volume cron tasks. The moment your Laravel 12 app processes thousands of webhooks, GST PDFs, or AI jobs per hour, switch to Horizon + Valkey 8 to achieve 10x throughput and eliminate MySQL lock contention. Check out n8n Production Hardening Pack or book a Laravel architecture review.