Setting up multiple Horizon workers

Set Kyar Wa Lar
Jun 12 · 3 min read

This time, I gonna write about setting up multiple horizons servers. Before you continue reading the article you should know what’s Laravel Horizon and how to setup Laravel+Horizon. If you still haven’t, go read the official documentation.

The article focus on how multiple Horizon is working and will try to explain to be easier setup for your own. The idea is when we have lots of workers that handle tons of process we gonna separate the worker process to different servers. Let’s take a look at the following diagram.

We will have an application server which sends queue to the queue server (Redis). And there are three Horizon servers which handle the queues which we define which queue to pick up. Let’s try to implement the above diagram.

(I will not go detail of how to setup step by step of Laravel and Horizon).

First, create a new Laravel app call app . And setup three horizon servers. I will name like the following horizon-one , horizon-two and horizon-three . Inside all those Horizon servers, setup your app Laravel application. After installing your application on all three Horizon servers, inside config/horizon.php add the following environment config.

One notice here, even we have the multiple servers like app , horizon-one , horizon-two , horizon-three we are still using the same code base.

The above environment will determine Horizon’s environment. Normally, Horizon checks the default application env which is not an ideal usage for us. Since we are creating multiple Horizon servers with the same code base and application might use the same environment. After setting up the Horizon’s environment, let’s continue another one.

Let’s imagine, you have three queue name notification , caching and default . Which queue from the application server. In that case, notification queue will handle by horizon-one server, caching queue will handle by horizon-two and default queue will handle by horizon-three .

In the real world, there can be multiple queues that handle by one horizon server.

Inside the config/horizon.php, add the following config after local block like the following

Inside the horizon-one horizon-two and horizon-three Laravel env , please don’t forget to add HORIZON_ENV which belong to which one. And yeah, that’s it!

Don’t forget to make connectable between horizon servers and redis server. And redis server with application server.

Comments, if you are not clear about the process. I will try to respond as soon as possible. Clap 👏 if this post helps you.

Set Kyar Wa Lar

Written by

Software Engineer at Carro.sg . Writer. Maker of 👨‍💻 https://www.myanmardevjobs.com , https://myanpx.comand http://ponekyimel.com Wanna be DataScience

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade