Blog
Laravel Horizon in Production: Queues, Timeouts, and Deploys
Laravel Horizon in production on Laravel 13: Redis queue config, supervisors and balancing, timeout vs retry_after, Supervisor, deploys, and failed jobs.
Muhammad Zubair Akhtar
Laravel Horizon is the dashboard and the config file that run your Redis queue workers. I am Zubair Akhtar, a senior software engineer in Lahore, Pakistan. On the Laravel apps I look after, the queue is where the slow work goes: webhook processing, emails, CRM syncs, exports. Horizon is how I keep that work visible and how I size the workers in code instead of in a pile of Supervisor programs.
This page covers a laravel queue setup that holds up in production with Horizon: the Redis connection, the supervisors in config/horizon.php, the timeout numbers that have to agree with each other, Supervisor, deploys, and failed jobs. Laravel cache comes up only where the queue depends on it. If you want this set up or reviewed on your own app, that is part of my Laravel development services.
Figure 1. Supervisor watches one process: php artisan horizon. Horizon starts and balances the workers behind it.
Versions this was written against
I read the Laravel 13.x Horizon documentation and the 13.x queues page on 8 November 2026. On that date Packagist listed laravel/horizon v5.50.1, published 13 October 2026, with illuminate/queue allowed up to ^13.0, and laravel/framework v13.40.0, published 3 November 2026. Horizon's Composer requirements include the ext-pcntl and ext-posix PHP extensions, so check those on the server before you install. Laravel 13 needs PHP 8.3 or newer.
I have not run these snippets for this article. They follow the documented examples with my own values. Try them on a staging host first.
When Horizon is the right tool
Horizon only works with Redis. The docs say your queue connection has to be redis in config/queue.php, and that Horizon is not compatible with Redis Cluster. If your app runs on the database driver or on SQS, plain queue:work under Supervisor is still the answer, and that setup is in deploy Laravel to a VPS.
I reach for Horizon when at least one of these is true:
- There is more than one queue, and they need different worker counts.
- Someone other than me needs to see failed jobs, throughput, and wait times without SSH.
- Worker settings should live in Git and change with a deploy, not by editing files in
/etc/supervisor/conf.d.
For a small app with one queue and a few jobs an hour, a single queue:work program is less to look after. Horizon is not a requirement for queues. It is a way to run them.
Install it
composer require laravel/horizon
php artisan horizon:install
horizon:install publishes config/horizon.php and app/Providers/HorizonServiceProvider.php. Horizon uses a Redis connection named horizon internally. The docs say that name is reserved, so do not give it to one of your own connections in config/database.php, or set it as the use option in config/horizon.php.
The Redis queue connection
Start with the connection, because Horizon inherits its timing from it. This is the 13.x Redis example with block_for set:
// config/queue.php
'redis' => [
'driver' => 'redis',
'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => env('REDIS_QUEUE_RETRY_AFTER', 90),
'block_for' => 5,
'after_commit' => true,
],
Three settings matter here.
retry_after is how long the connection waits before it hands a job that is still processing to another worker. At 90, a job that has run for 90 seconds without being released or deleted goes back on the queue. The queues page says to set it to the longest a job should reasonably take.
block_for makes the worker wait on Redis for a job instead of polling in a loop. The docs warn that 0 blocks indefinitely, and that a worker blocked that way does not handle SIGTERM until the next job arrives. I keep it at a few seconds so a deploy can stop the worker.
after_commit is the documented setting I turn on most often. With it set to true, a job dispatched inside a database transaction waits until the transaction commits. Without it, a worker can pick up a job for an order row that does not exist yet. The same switch also delays queued listeners, mailables, notifications, and broadcast events until the commit. If you only need it for one job, the docs show ->afterCommit() on the dispatch instead.
Supervisors and balancing in config/horizon.php
The environments key holds one block per APP_ENV. Each block has one or more supervisors, and each supervisor manages a pool of worker processes for the queues you give it. The default file has supervisor-1 for production and local. Add a block for every environment that runs Horizon, or a * wildcard block.
This is the production block I start from. It is based on the documented examples:
// config/horizon.php
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default', 'notifications'],
'balance' => 'auto',
'autoScalingStrategy' => 'time',
'minProcesses' => 1,
'maxProcesses' => 6,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'tries' => 3,
'timeout' => 60,
'backoff' => [10, 60, 300],
'memory' => 128,
'maxTime' => 3600,
'maxJobs' => 1000,
],
'supervisor-images' => [
'connection' => 'redis',
'queue' => ['images'],
'balance' => 'simple',
'processes' => 1,
'tries' => 2,
'timeout' => 80,
],
],
],
Queue order does not mean priority under auto
This is the setting I see misread the most. With plain workers, queue:work --queue=high,default empties high before it touches default. Under Horizon's auto strategy, the docs say the order of the queue array does not set priority. Horizon assigns workers from queue load using the autoScalingStrategy: time (estimated time to clear), size (job count), or log (logarithm of the job count, so one huge queue does not take every worker).
If one queue really must win, you have two documented options:
- Separate supervisors. Give the important queue its own supervisor and its own process limits. That is why
imagessits insupervisor-imagesabove. A heavy job type on its own capped pool cannot take CPU from everything else. 'balance' => false. Horizon then processes queues strictly in the order listed, like the default queue system, and it still scales betweenminProcessesandmaxProcesses.
simple splits a fixed processes count evenly across the listed queues and does not scale.
Size the pool for the box you actually have
maxProcesses is a total across all queues for that supervisor, and minProcesses is per queue under auto. On a 2 GB VPS I would not copy the documented maxProcesses => 10 until I have watched memory under real load. Each worker is a full PHP process with the framework booted. The memory option, 128 MB by default, restarts a worker that grows past it. maxJobs and maxTime restart workers after a set number of jobs or seconds. Both default to 0, which means off. The docs recommend periodic restarts for long-running processes to guard against leaks, so I set both.
Timeouts: four numbers that must agree
Most duplicate-job and killed-job problems I have traced came down to these numbers disagreeing. The docs give the rules. I keep them in one place:
- Job timeout (
#[Timeout(45)]on the class) is the longest that one job may run. - Horizon supervisor
timeouthas to be greater than any job-level timeout. Underautobalancing, Horizon treats in-progress workers as hanging and force-kills them after this timeout when it scales down. If it is shorter than a job's own timeout, that job can be cut off mid-run. retry_afterhas to be at least a few seconds longer than the Horizon timeout. If it is shorter, a second worker picks the job up while the first one is still running, and the job runs twice.- Supervisor
stopwaitsecshas to be longer than your longest-running job, or Supervisor kills a job during a deploy that Horizon was trying to let finish.
Figure 2. Example values. Each number has to be smaller than the one above it, and stopwaitsecs has to outlast the slowest job.
The images supervisor above uses timeout => 80. That still fits under retry_after => 90, but only just. If image jobs need several minutes, put them on their own Redis connection with a larger retry_after instead of stretching one connection to fit every job.
One more limit from the queues page: an outgoing HTTP call or socket may ignore the job timeout. Set connect and request timeouts on the HTTP client as well, so a stuck third-party API fails the job instead of hanging the worker.
Tries, backoff, and middleware
Horizon's tries works like --tries. If you leave it out, a job gets one attempt unless the class sets $tries or #[Tries], and the class wins. An attempt is used up when the job throws, when it calls $this->release(), when it times out, and when WithoutOverlapping or RateLimited cannot get its lock and releases it. That last one surprises people. A job behind WithoutOverlapping with one try can fail without ever running handle(). Raise tries, and use #[MaxExceptions(3)] so real exceptions still stop it.
backoff accepts an array. [10, 60, 300] waits 10 seconds before the first retry, 60 before the second, and 300 before every retry after that. For webhook jobs I also make the job safe to run twice, because a retry after a partial success is still a second run. The receiving side of that is in webhooks explained.
Where Laravel cache fits
I am keeping this short, because cache tuning is a separate topic. The queue depends on the cache in three places:
queue:restartstores its restart signal in the cache. The queues page says to configure a real cache driver before relying on it. This matters if you still run plainqueue:worknext to Horizon.- Unique jobs (
ShouldBeUnique) take a lock through the default cache driver.uniqueVia()can point that lock at another store. WithoutOverlappingneeds a cache driver that supports atomic locks: memcached, redis, dynamodb, database, file, or array. On more than one server,fileandarraylocks are local to each machine, so I useredisfor the cache store too.
Supervisor, the dashboard, and deploys
Keep php artisan horizon alive
Horizon is one long-running command. Supervisor restarts it if it exits. This is the documented horizon.conf with the paths changed for the release layout from my VPS deploy guide:
[program:horizon]
process_name=%(program_name)s
command=php /var/www/laravel-app/current/artisan horizon
autostart=true
autorestart=true
user=deploy
redirect_stderr=true
stdout_logfile=/var/www/laravel-app/shared/storage/logs/horizon.log
stopwaitsecs=3600
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start horizon
The command goes through the current symlink. A hardcoded release path keeps running old code after the symlink moves. One program runs the whole pool. You do not add numprocs here, because Horizon starts the workers itself. If the app runs in containers, Horizon gets its own long-running service. The image layout is in the Laravel Docker setup.
Deploy with horizon:terminate
The deploy step is php artisan horizon:terminate, not queue:restart. The docs say Horizon finishes the jobs it is running, then exits, and Supervisor starts it again on the new code. I run it after the symlink swap, in the same place my deploy script calls queue:restart for plain workers.
horizon:pause and horizon:continue stop and resume processing without exiting. horizon:status and horizon:supervisor-status supervisor-1 are what I check from SSH after a deploy.
Maintenance mode matters here. While the app is down for maintenance, Horizon does not process jobs unless the supervisor has 'force' => true. If a migration takes ten minutes, the queue just waits, which is usually what you want.
Lock down /horizon
The dashboard lives at /horizon. Outside local it is gated by viewHorizon in HorizonServiceProvider:
protected function gate(): void
{
Gate::define('viewHorizon', function (User $user) {
return in_array($user->email, [
'[email protected]',
]);
});
}
Job payloads, tags, and exception traces show up on that page. Treat it as an admin screen. If your app uses a CSP, the docs show Horizon::cspNonce() in a middleware listed under the middleware key of config/horizon.php.
Failed jobs, metrics, and alerts
When a job runs out of attempts, it goes to the failed_jobs table. New apps usually ship the migration. If yours does not, php artisan make:queue-failed-table creates it. Horizon shows failed jobs in the dashboard, and the CLI covers the rest:
php artisan queue:failed
php artisan queue:retry ce7bb17c-cdd8-41f0-a8ec-7b4fef4e5ece
php artisan horizon:forget 5
php artisan queue:prune-failed --hours=48
queue:prune-failed keeps 24 hours by default, so pass --hours if you want a longer window to investigate.
Two scheduled items make the dashboard useful:
// routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('horizon:snapshot')->everyFiveMinutes();
Without horizon:snapshot, the metrics page stays empty. metrics.trim_snapshots limits how many snapshots are kept, not how old they are, so retention depends on how often the snapshot runs.
For alerts, Horizon::routeMailNotificationsTo() and routeSlackNotificationsTo() in the service provider fire when a queue waits longer than its waits threshold. That threshold is 60 seconds unless you set it per connection:queue pair. Set 'redis:notifications' => 30 for anything a customer is waiting on, and 0 to turn alerts off for batch queues.
Tags help when one customer reports a problem. Horizon tags a job with any Eloquent model it carries, such as App\Models\Order:1042, so you can search the dashboard by that tag. A tags() method on the job adds your own tags, for example a HubSpot portal id on the jobs from a HubSpot CRM integration.
My production checklist for Laravel Horizon
QUEUE_CONNECTION=redis, no Redis Cluster, and nothing else using thehorizonconnection nameafter_commit => trueon the Redis connection, orafterCommit()on the jobs that need itblock_forof a few seconds, not0- Job
#[Timeout]< Horizontimeout<retry_after, andstopwaitsecs> slowest job - Heavy job types on their own supervisor with a low
maxProcesses triesraised for any job behindWithoutOverlappingorRateLimitedmemory,maxJobs, andmaxTimeset so workers restart regularly- Supervisor command through
current/artisan, andhorizon:terminatein the deploy viewHorizongate restricted,horizon:snapshotscheduled, wait alerts routed somewhere a person readsqueue:prune-failedscheduled sofailed_jobsdoes not grow forever
API endpoints that hand work to the queue still need the versioning and rate limits from REST API development with Laravel. The queue only makes the slow part asynchronous.
Work with me
I set up and audit Laravel queues as part of Laravel development. Send me your config/queue.php, config/horizon.php, and the Supervisor program file. I will start with the timeout ladder, because that is where duplicate and killed jobs usually come from, and then check whether the deploy actually restarts Horizon on the new code.
