Mastering Laravel 12 Horizon: Real-Time Queue Monitoring Made Elegant
In modern web applications, queues play a crucial role in improving performance, scalability, and user experience. Whether it's sending emails, processing image uploads, or executing time-consuming tasks, Laravel queues help offload heavy jobs from the main request-response cycle.
But how do you monitor, manage, and optimize those background jobs?
Meet Laravel Horizon – a beautifully designed dashboard and powerful queue manager built specifically for Laravel's Redis-based queue system.
In this blog, we'll explore what Laravel Horizon is, why it's a game-changer, how to set it up, and best practices for using it in production.
🌟 What is Laravel Horizon?
Laravel Horizon is an elegant queue monitoring dashboard for Laravel applications that use the Redis queue driver. Developed by the Laravel team, it provides:
- A real-time web dashboard to monitor jobs
- Insight into failed, pending, and completed jobs
- Job retry and tag filtering capabilities
- Metrics on throughput and runtime
- Queue balancing for better performance
- Auto-scaling workers in production
Horizon is tailored exclusively for Redis, making it ultra-fast and efficient.
🎯 Why Use Horizon?
Here’s why Laravel Horizon is a must-have for serious Laravel developers:
| Feature | Benefit |
|---|---|
| ✅ Real-time Monitoring | See job status updates live as they happen |
| 📊 Metrics & Analytics | View average job runtime, throughput, and job trends |
| 💥 Failed Job Management | Easily retry or inspect failed jobs |
| ⚙️ Queue Load Balancing | Auto-adjust worker queues for optimal performance |
| 🚦 Tag-Based Filtering | Track specific job types using custom tags |
| 📁 Redis Integration | Seamless performance on Laravel’s Redis queue |
🔧 Installing Laravel Horizon
Installing Horizon is as easy as running a few Artisan commands:
1. Require Horizon
composer require laravel/horizon
2. Publish Configuration
php artisan horizon:install
This will publish the config/horizon.php file, where you can configure workers, supervisors, and environments.
3. Run Horizon
php artisan horizon
Visit http://your-app.test/horizon and enjoy your new dashboard!
🧠 How Horizon Works
Laravel Horizon works by managing supervisors — processes that monitor your queue workers. In config/horizon.php, you define the number of workers, queues, balance strategy, and connection.
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
],
Horizon uses Redis not just to store queued jobs, but also for metrics, tags, and recent job tracking.
📺 Exploring the Dashboard
Here’s what the Horizon dashboard offers:
1. Dashboard View
Gives you an overview of queue metrics like job runtime, queue wait time, and throughput.
2. Jobs Tab
Lists recent jobs with their statuses (pending, completed, failed). You can view detailed info, tags, and retry jobs directly from the UI.
3. Failed Jobs
View the error stack trace and retry failed jobs with a single click.
4. Metrics
See graphs of queue performance over time—perfect for debugging performance issues or traffic spikes.
5. Supervisors & Workers
View each worker's real-time activity, restart them, and monitor queue health.
📡 Deploying Horizon in Production
Horizon runs as a long-lived process. In production, you should daemonize it using a process manager like Supervisor or systemd.
Example Supervisor config:
[program:horizon]
process_name=%(program_name)s
command=php /path-to-your-app/artisan horizon
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
stdout_logfile=/path-to-your-app/storage/logs/horizon.log
Restart Supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start horizon
🛡️ Securing Horizon
By default, Horizon is accessible to anyone who visits /horizon. In production, you should restrict access.
Update the HorizonServiceProvider:
Horizon::auth(function ($request) {
return auth()->check() && auth()->user()->isAdmin();
});
You can also use Laravel Sanctum or custom middleware for more control.
🧩 Tagging Jobs for Better Insights
You can tag jobs using the tags() method in your job class:
public function tags()
{
return ['order:'.$this->orderId];
}
This allows you to track jobs related to specific users, orders, or events directly in Horizon.
⚖️ Horizon vs Laravel Queue Worker
| Feature | php artisan queue:work |
Laravel Horizon |
|---|---|---|
| Monitoring UI | ❌ | ✅ Real-time dashboard |
| Metrics | ❌ | ✅ Job runtime, wait time, graphs |
| Auto-Scaling | ❌ Manual configuration | ✅ Balance and scaling options |
| Retry Jobs UI | ❌ | ✅ Click-to-retry failed jobs |
| Tags & Filtering | ❌ | ✅ Tags, filters, tracking |
If your project has growing queue demands, Horizon is a no-brainer upgrade.
💡 Best Practices with Horizon
- ✅ Use tags on important jobs for tracking
- ✅ Monitor throughput to optimize performance
- ✅ Set up alerts for job failures (via Slack, email)
- ✅ Regularly review failed jobs and retry appropriately
- ✅ Run Horizon with Supervisor for stability
- ✅ Protect the dashboard with auth middleware
🏁 Conclusion
Laravel Horizon is more than just a pretty interface—it's a powerful tool for building, maintaining, and scaling queue-driven applications. With live metrics, a polished UI, and Redis-powered performance, Horizon gives developers the tools they need to confidently manage background processing in production.
Whether you’re running a SaaS platform, e-commerce store, or real-time notification system, Horizon gives you full visibility and control over your job queues.
🧠 Code with confidence. Monitor with elegance. That’s the power of Laravel Horizon.
Projects to explore next
Source-code projects from the KritiMyantra catalogue. Check each project's details before buying.
Flask Authentication System (Free Version) - Kritim Yantra
🛠 Features✔ Google & GitHub Authentication✔ User Registration & Login✔ Profile/Dashboard Access✔ Secure & Mi...
Flask Blog CMS with Admin Dashboard — Python Source Code
A Flask-based blogging website with a built-in admin dashboard. Manage articles, images, categories, tags and featured p...
Laravel 12 + ReactJS Starter Kit: Add Multi-Language Support (Arabic, English, Spanish) with Blog CRUD
🚀 Installation & Setup Download & Extract Get the ZIP from kritimyantra.com and extract it. Includes preconfigu...
Comments
No comments yet. Be the first to comment.
Sign in to join the discussion.