Deferred Queue Driver in Laravel 12.35
- Introduction
- How deferred queue driver works
- Configuration
- Combining Deferred with the Failover Queue Driver
- When to Use the Deferred Queue Driver
- Summary
Introduction
Laravel 12.35 adds a new queue driver called deferred, designed to process queued jobs after the HTTP response is sent back to the client, all within the same PHP process.
Unlike typical queue drivers (database, redis, sqs, etc.) that rely on external workers, the deferred driver lets you defer non-critical tasks like sending emails, logging, or analytics, until the request is complete.
How deferred queue driver works
Here’s what happens under the hood when using the deferred queue driver:
- You dispatch a job normally using
dispatch(). - Once the HTTP response is sent to the user, Laravel automatically processes the deferred jobs synchronously within the same PHP process after the response has been sent out to the user.
Configuration
To use the deferred queue driver, add a new connection in your config/queue.php file:
'connections' => [ 'deferred' => [ 'driver' => 'deferred', ],],
Set it globally in your .env:
QUEUE_CONNECTION=deferred
Then, in your code, you can:
SendWelcomeEmail::dispatch($user);
Combining Deferred with the Failover Queue Driver
You can combine the deferred driver with Laravel’s failover queue driver to ensure maximum reliability.
In this setup, Laravel will first try to push jobs to your main database queue. If that fails (for example, due to a temporary connection issue), it will fall back to the deferred driver, which ensures the job still runs immediately after the HTTP response is sent.
Here’s how to configure it in config/queue.php:
'connections' => [ 'failover' => [ 'driver' => 'failover', 'connections' => ['database', 'deferred'], ],],
Then, in your .env file:
QUEUE_CONNECTION=failover
Now when you dispatch a job:
SendWelcomeEmail::dispatch($user);
Here’s the flow:
- Laravel attempts to push the job to the database queue first.
- If the database queue connection fails, Laravel automatically falls back to the deferred driver.
- The deferred driver ensures the job runs immediately after the response is sent to the user preventing job loss even if your main queue is down.
This hybrid setup provides both reliability and speed:
- Jobs are normally handled by your primary queue system (e.g., database workers).
- If it’s unavailable, they’re executed instantly after the response, thanks to the deferred fallback.
When to Use the Deferred Queue Driver
The deferred queue driver is ideal for:
- Sending transactional emails right after a request.
- Logging analytics or metrics post-response.
- Broadcasting events or notifications that don’t affect the immediate user experience.
- Any short, non-critical task that should run after the response but doesn’t need a dedicated worker.
However, avoid it for:
- Long-running or resource-heavy jobs.
- Tasks that require retry logic or distributed processing (use
redis,sqs, ordatabaseinstead).
Summary
The Deferred Queue Driver introduced in Laravel 12.35 provides a simple but powerful way to run queued jobs after the HTTP response is sent all without extra setup or workers.
When paired with the Failover Queue Driver, it creates a safe and efficient hybrid approach: immediate post-response execution with reliable fallback protection.
Stay Updated.
I'll you email you as soon as new, fresh content is published.