Tech Verse Logo
Enable dark mode
Laravel Failover Queue Driver: Ensuring Reliable Job Processing

Laravel Failover Queue Driver: Ensuring Reliable Job Processing

•Updated •3 min read

Add a connection with 'driver' => 'failover' to config/queue.php and list the connections it should try in order, such as redis then database, under its connections key. Set QUEUE_CONNECTION=failover or dispatch with onConnection('failover'), and Laravel pushes each job to the next connection when one fails, so a Redis outage doesn't lose dispatched jobs.

Laravel's failover queue driver improves the reliability of queued job processing. It lets you define multiple queue connections in order of priority, so a job still gets queued even if the primary queue system is down.

In production environments, where uptime and consistent job delivery are critical, the failover driver can be a game-changer.

How the Failover Queue Driver Works

The failover driver acts as a wrapper around multiple queue connections. When a job is dispatched, Laravel will attempt to push it to the first connection in your list. If that connection fails — for example, if Redis is temporarily unavailable — Laravel automatically tries the next connection until the job is successfully queued.

This mechanism ensures high availability Laravel queues and protects your application from lost jobs or downtime.

Defining a Failover Queue Connection

You can configure the failover driver in your config/queue.php file. Here’s an example:

'connections' => [
    'failover' => [
        'driver' => 'failover',
        'connections' => [
            'redis',
            'database',
        ],
    ],

    'redis' => [
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => 90,
    ],

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],
],

In this setup:

  • Laravel will first try Redis to push jobs.

  • If Redis is unavailable, the system will fall back to the database queue, providing a job queue redundancy mechanism.

Setting the Default Queue Connection

Once your failover driver is configured, you can set it as the default queue connection in your .env file:

QUEUE_CONNECTION=failover

This ensures that all queued jobs automatically use the failover logic, improving reliable job processing in Laravel.

Running a Worker for Every Connection

The failover driver only decides where a job is pushed. Workers don't read from failover; they read from the real connections behind it. If you only run a Redis worker, every job that failed over sits in the jobs table until someone notices, which is the outage you were trying to avoid. Start at least one worker for each connection in the list:

php artisan queue:work redis
php artisan queue:work database

Give both their own program in Supervisor (or whatever keeps your workers alive) so the database worker is already running when Redis goes down. If you use Horizon, remember it only manages Redis queues: run a plain php artisan queue:work database process alongside it. Connections on the sync, deferred or background drivers don't need a worker, since they run the job in the current PHP process.

Two more things worth knowing. When a push fails over, Laravel dispatches the Illuminate\Queue\Events\QueueFailedOver event, so listen for it and report it, or you won't know Redis was down. And failover only covers new pushes: jobs already sitting in Redis when it goes down stay there until it comes back.

When to Use the Failover Driver

The failover queue driver is ideal for:

  • Applications where job reliability is essential.

  • High-availability environments with multiple queue backends (Redis, SQS, Database).

  • Systems where downtime of one queue system should not interrupt job processing.

By using multiple connections, you ensure that your application can maintain continuous job dispatch even under failures.

Example: Dispatching Jobs With Failover

use App\Jobs\SendEmailJob;

SendEmailJob::dispatch($user)
    ->onConnection('failover');

Laravel will automatically try to enqueue the job to Redis first. If Redis is down, it will failover to the database queue, ensuring no jobs are lost.

Benefits of the Failover Queue Driver

  • High reliability: Jobs are not lost if the primary queue fails.

  • Automatic fallback: Laravel seamlessly switches between connections.

  • Ease of configuration: Only a few lines in queue.php are needed.

  • Production-ready: Ideal for applications that require robust job delivery.

Conclusion

Laravel’s failover queue driver ensures uninterrupted job dispatching by gracefully falling back to backup connections. This small configuration change significantly improves your application's queue system reliability, making it suitable for high-availability environments and critical job processing.

By implementing the failover driver, you gain a robust queue system that combines Redis speed with database reliability, ensuring continuous job delivery even during unexpected downtime.

WRITTEN BY

Full Stack Software Engineer | Laravel · Next.js · AWS

Full Stack Software Engineer with 7+ years of experience building scalable, secure web applications with Laravel, PHP, React, Next.js, and AWS for SaaS, CRM, telecom, and e-commerce companies. Specialized in cloud telephony (FreeSWITCH, SMPP, WebRTC): increased concurrent call capacity by 40% and cut report queries to under 500 ms. Author of open-source Laravel packages with 10K+ downloads on Packagist. Led a team of 4 engineers and shipped production systems for clients in the UAE, USA, India, Saudi Arabia, and Bangladesh.

How we research, write and check articles

    Latest Posts

    View All

    Next.js Middleware Authentication and Token Refresh Flows

    Next.js Middleware Authentication and Token Refresh Flows

    Livewire Performance Optimization Under High Load

    Livewire Performance Optimization Under High Load

    Configuring Nginx Upstream Keepalive for Node Backends

    Configuring Nginx Upstream Keepalive for Node Backends

    Enforcing Immutable State Patterns in React

    Enforcing Immutable State Patterns in React

    FastAPI Dependency Overrides for Integration Testing

    FastAPI Dependency Overrides for Integration Testing

    Stopping Layout Shifts in Next.js Dynamic Imports

    Stopping Layout Shifts in Next.js Dynamic Imports

    Optimizing Agentic Tool Calling Latency

    Optimizing Agentic Tool Calling Latency

    Fixing React Server Component Serialization Errors

    Fixing React Server Component Serialization Errors

    Next.js Route Handler Streaming with ReadableStream

    Next.js Route Handler Streaming with ReadableStream

    React Form Performance: Uncontrolled Inputs and FormData

    React Form Performance: Uncontrolled Inputs and FormData