Laravel Horizon: setup and monitoring in production
Setting up Horizon for the first time. Documentation covers installation but not the operational side: what metrics to watch, what alerts to set up, common failure patterns.
The key metrics are throughput (jobs completed per minute), wait time (time in queue before pickup), and failed jobs count. Set up Horizon Pulse or export metrics to your monitoring stack.
Failed jobs are the most critical alert. A spike in failures usually means either an external API is down or you deployed a bug. Set an alert on failed_jobs count exceeding 10 in 5 minutes.
Horizon runs as a long-lived process. Use Supervisor to keep it running. Restart Horizon after each deploy (it loads a snapshot of the queue workers at start). Without a restart after deploy, workers run old code.
The balance setting in horizon.php sets worker count per queue. Tune this based on actual throughput measurements, not guesses. Horizon auto-scaling adjusts within the limits you set.
Prune the failed_jobs table periodically. Long-running Horizon instances accumulate failed jobs and querying them gets slow. A scheduled command running horizon:forget-failed --hours=72 keeps the table clean.
Horizon dashboard should not be publicly accessible. Gate it behind auth in HorizonServiceProvider. We forgot this on a staging environment for two weeks before someone noticed.
```php blocks are runnable.