[{"data":1,"prerenderedAt":29},["ShallowReactive",2],{"$fl6iSieXpRhV3EClv74kyOKBU3iBN-u2atXtUs--SUIE":3},{"slug":4,"title":5,"description":6,"date":7,"tags":8,"draft":13,"readingMinutes":14,"html":15,"related":16},"laravel-horizon","Laravel Horizon: The Defaults I Change Before Production","Laravel Horizon 5.51 on Laravel 13: the queue settings that bite in production, tries, timeout vs retry_after, auto balancing and the empty metrics page.","2026-11-16",[9,10,11,12],"laravel","horizon","redis","queues",false,4,"\u003Cp>Laravel Horizon is a dashboard and a config file for Laravel queues that run on Redis. That&#39;s it. It doesn&#39;t replace the queue, it supervises the workers, decides how many run on which queue, and shows you what they did. If your queue driver is \u003Ccode>database\u003C/code> or SQS, Horizon isn&#39;t for you. It needs \u003Ccode>redis\u003C/code>, and the \u003Ca href=\"https://laravel.com/docs/13.x/horizon\">Laravel 13 docs\u003C/a> still say it doesn&#39;t work with Redis Cluster.\u003C/p>\n\u003Cp>Versions as I write this, on November 16, 2026: laravel/horizon 5.51.0 (released November 2) and Laravel 13.42.\u003C/p>\n\u003Cp>Installing it takes two commands, \u003Ccode>composer require laravel/horizon\u003C/code> and \u003Ccode>php artisan horizon:install\u003C/code>. The defaults it gives you are fine for a laptop. A few of them are wrong for a real server, and the docs mention each one in passing, usually inside a warning box. These are the ones I change first.\u003C/p>\n\u003Ch2>tries defaults to 1\u003C/h2>\n\u003Cp>If you don&#39;t set \u003Ccode>tries\u003C/code> on the supervisor and the job class has no \u003Ccode>$tries\u003C/code>, Horizon gives each job one attempt. One. A payment webhook that hits a timeout from Stripe once is now a failed job, and nothing retries it.\u003C/p>\n\u003Cp>I set \u003Ccode>tries\u003C/code> on every supervisor and override it on the jobs that need more. There&#39;s one catch the docs call out: middleware like \u003Ccode>WithoutOverlapping\u003C/code> and \u003Ccode>RateLimited\u003C/code> use up attempts when they release a job back to the queue. A rate-limited job with \u003Ccode>tries =&gt; 3\u003C/code> can fail without its code ever running. For those I use \u003Ccode>tries =&gt; 0\u003C/code> (unlimited) with \u003Ccode>$maxExceptions\u003C/code> on the job, so real exceptions still stop it.\u003C/p>\n\u003Cp>Add \u003Ccode>backoff\u003C/code> while you&#39;re there. \u003Ccode>&#39;backoff&#39; =&gt; [1, 5, 10]\u003C/code> waits 1, 5, then 10 seconds between retries. Without it a failing job retries instantly, which is exactly the wrong thing to do to an API that is already struggling.\u003C/p>\n\u003Ch2>timeout has to be shorter than retry_after\u003C/h2>\n\u003Cp>This is the setting that causes the strangest bugs. Horizon&#39;s \u003Ccode>timeout\u003C/code> is how long a worker may run a job before it&#39;s killed. \u003Ccode>retry_after\u003C/code>, in \u003Ccode>config/queue.php\u003C/code>, is how long Redis waits before it assumes a job was lost and hands it to another worker.\u003C/p>\n\u003Cp>If \u003Ccode>retry_after\u003C/code> is shorter than the time a job really takes, a second worker picks up the same job while the first one is still working on it. You get two emails, two charges, two PDFs. The docs say \u003Ccode>timeout\u003C/code> should be &quot;at least a few seconds shorter&quot; than \u003Ccode>retry_after\u003C/code>. I keep a bigger gap than that, and I set both on purpose, never leave them at whatever the stub had.\u003C/p>\n\u003Cimg src=\"/blog/laravel-horizon/horizon-balance-decision.webp\" alt=\"Choosing a Laravel Horizon balance strategy: auto, simple or false, and when each one fits\" width=\"1600\" height=\"900\" loading=\"lazy\">\u003Cp>There&#39;s a third number in the same family. When the \u003Ccode>auto\u003C/code> strategy scales workers down, Horizon treats busy workers as hanging and force-kills them after the Horizon timeout. So the supervisor \u003Ccode>timeout\u003C/code> must be larger than any job&#39;s own \u003Ccode>$timeout\u003C/code>, or long jobs get cut off mid-way during a quiet moment. And if you run Horizon under Supervisor, \u003Ccode>stopwaitsecs\u003C/code> has to be longer than your longest job too, or deploys kill work in progress.\u003C/p>\n\u003Ch2>auto balancing ignores your queue order\u003C/h2>\n\u003Cp>People write \u003Ccode>&#39;queue&#39; =&gt; [&#39;high&#39;, &#39;default&#39;]\u003C/code> and assume \u003Ccode>high\u003C/code> goes first. With the default \u003Ccode>auto\u003C/code> strategy it doesn&#39;t. Horizon gives workers to whichever queue looks busiest by its \u003Ccode>autoScalingStrategy\u003C/code> (\u003Ccode>time\u003C/code>, \u003Ccode>size\u003C/code> or \u003Ccode>log\u003C/code>), and the order in the array means nothing.\u003C/p>\n\u003Cp>If priority matters, I use two supervisors: one for the important queue with its own \u003Ccode>minProcesses\u003C/code>, one for everything else. Heavy work like image processing or PDF rendering gets its own supervisor with \u003Ccode>maxProcesses\u003C/code> of 1 or 2, so a batch of 5,000 thumbnails can&#39;t eat every CPU on the box. If you want strict order and nothing clever, \u003Ccode>&#39;balance&#39; =&gt; false\u003C/code> processes queues in the listed order and still scales up when jobs pile up.\u003C/p>\n\u003Ch2>Workers that never restart\u003C/h2>\n\u003Cp>The defaults are \u003Ccode>memory =&gt; 128\u003C/code>, \u003Ccode>maxJobs =&gt; 0\u003C/code> and \u003Ccode>maxTime =&gt; 0\u003C/code>. So a worker restarts when it passes 128 MB, and otherwise runs forever. Long-running PHP processes leak, slowly, especially with big Eloquent collections or SDKs that cache things in static properties. I set \u003Ccode>maxJobs\u003C/code> to something like 1,000 and \u003Ccode>maxTime\u003C/code> to an hour. A restarted worker costs a fraction of a second.\u003C/p>\n\u003Ch2>The dashboard is closed in production, and that&#39;s correct\u003C/h2>\n\u003Cp>\u003Ccode>/horizon\u003C/code> works only in the \u003Ccode>local\u003C/code> environment until you edit the \u003Ccode>viewHorizon\u003C/code> gate in \u003Ccode>HorizonServiceProvider\u003C/code>. People hit a 403 after deploying and &quot;fix&quot; it by returning \u003Ccode>true\u003C/code>. Don&#39;t. The dashboard shows job payloads, and payloads often hold emails, order data or tokens. Put real admin emails or a role check in that gate.\u003C/p>\n\u003Cp>Related: Horizon reserves a Redis connection named \u003Ccode>horizon\u003C/code>. Name one of your own connections that and things break in confusing ways.\u003C/p>\n\u003Ch2>The metrics page is empty\u003C/h2>\n\u003Cp>The Metrics tab stays empty until you schedule \u003Ccode>horizon:snapshot\u003C/code> every five minutes:\u003C/p>\n\u003Cpre>\u003Ccode class=\"language-php\">Schedule::command(&#39;horizon:snapshot&#39;)-&gt;everyFiveMinutes();\n\u003C/code>\u003C/pre>\n\u003Cp>That needs the scheduler running, which is its own cron entry or process. Retention is a count of snapshots, not days, so with \u003Ccode>trim_snapshots\u003C/code> at 24 and a five-minute schedule you keep two hours of history.\u003C/p>\n\u003Ch2>Deploying it\u003C/h2>\n\u003Cp>Horizon is one long-running process, \u003Ccode>php artisan horizon\u003C/code>, and it needs something to restart it when it dies. The docs show Supervisor. My preference is a systemd unit with \u003Ccode>Restart=always\u003C/code>, which does the same job without another package. Either way, your deploy script runs \u003Ccode>php artisan horizon:terminate\u003C/code> after the new code is in place. It lets current jobs finish, exits, and the process manager starts it again on the new code. Forget that step and the workers run last week&#39;s code until the next reboot.\u003C/p>\n\u003Cp>If you&#39;d rather not build all of this into a queue setup yourself, or you have one that keeps &quot;losing&quot; jobs, \u003Ca href=\"https://calendly.com/director-norsky/meeting\">book a call with me\u003C/a>. For the Node side of the same problem, I wrote about \u003Ca href=\"/blog/bullmq\">BullMQ\u003C/a>, and if you&#39;re choosing the Redis underneath, \u003Ca href=\"/blog/valkey-vs-redis\">Valkey vs Redis\u003C/a>.\u003C/p>\n",[17,21,25],{"slug":18,"title":19,"description":20},"redis-streams","Redis Streams in Node: Consumer Groups Without the Surprises","Redis Streams with consumer groups in Node.js, checked November 2026: the worker loop, the pending list, claiming stuck messages, trimming, and Redis 8's new commands.",{"slug":22,"title":23,"description":24},"laravel-reverb","Laravel Reverb in Production: The Limits to Raise First","Laravel Reverb runs WebSockets inside your Laravel app. What install:broadcasting sets up, and the five server limits that stop it near 1,000 users.",{"slug":26,"title":27,"description":28},"valkey-vs-redis","Valkey vs Redis: Which One I'd Run in Late 2026","Valkey vs Redis in October 2026: licenses, Valkey 9.1 vs Redis 8.10, the data-file break after Redis 7.4, and ElastiCache's 20-33% Valkey discount.",1795910047357]