QA
Senior LevelLaravel

How do you tune Horizon auto-scaling strategies based on queue length and CPU metrics?

❓ Interview Prompt: Explain Horizon balancing strategies (simple, auto, false), queue wait time calculation, and tuning minProcesses / maxProcesses.

Laravel Horizon's 'auto' balancing strategy uses workload algorithms to adjust worker pool allocations across queues dynamically:

How Horizon Scales:

Calculates Queue Wait Time (how long job has been waiting in Redis). If wait time on a high-priority queue rises, Horizon shifts worker processes from low-priority queues to high-priority queues instantly up to 'maxProcesses' bounds!

Code Implementation Example

php
<?php
// Horizon auto-scaling configuration tuned for heavy workloads
'production' => [
    'supervisor-auto' => [
        'connection' => 'redis',
        'queue' => ['default', 'emails', 'exports'],
        'balance' => 'auto',
        'autoScalingStrategy' => 'time', // Scale by wait time
        'minProcesses' => 2,
        'maxProcesses' => 20,
        'balanceMaxShift' => 2,
    ],
];
💡Tuning Horizon supervisor auto-scaling rules based on queue wait times.
🎯 Interview Key Takeaway

Configure Horizon balance='auto' with wait time metrics to dynamically allocate workers during queue traffic spikes.

#Horizon#Auto-Scaling#Queue Wait Time#Senior
Back to all Laravel Questions→

More Laravel Interview Questions

Beginner LevelLaravel

How does the Laravel Service Container manage Dependency Injection and Bindings?

Beginner LevelLaravel

How does Routing work in Laravel including Named Routes and Route Parameters?

Beginner LevelLaravel

What is Blade Templating and how do custom directives work?