Picture this. A user signs up on your app. Your code sends a welcome email. The email service takes 2 seconds to respond. The user stares at a loading spinner for 2 seconds before seeing the success page.
That is a terrible experience. And it is completely unnecessary.
Queues let you say: "Do this later, in the background. The user does not need to wait." The user sees the success page instantly. The email gets sent a second later. Everyone is happy.
How queues work
When you push a job to a queue, you are basically leaving a note that says "please do this task." A separate process — the queue worker — picks up that note and does the work. The web request that created the note is already done and the user has their response.
Setting up
For development, the sync driver runs jobs immediately (no worker needed). For production, use Redis:
QUEUE_CONNECTION=redisCreating a job
php artisan make:job SendWelcomeEmailclass SendWelcomeEmail implements ShouldQueue {
public function __construct(private User $user) {}
public function handle(): void {
Mail::to($this->user)->send(new WelcomeMail($this->user));
}
}Dispatching it
// In your controller, after creating the user
SendWelcomeEmail::dispatch($user);
// Want to delay it? Easy.
SendWelcomeEmail::dispatch($user)->delay(now()->addMinutes(5));That is it. The controller returns immediately. The job runs in the background.
Running the worker
php artisan queue:work redisIn production, use Supervisor to keep the worker running even if it crashes:
[program:laravel-worker]
command=php /var/www/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=trueWhat happens when a job fails?
Jobs can fail — the email service might be down, the API might time out. Set a retry count:
public int $tries = 3;
public int $backoff = 60; // wait 60 seconds between retriesFailed jobs land in the failed_jobs table. You can inspect them and retry:
php artisan queue:retry allWhat else should go in a queue?
Anything that takes more than half a second and does not need to happen before the user gets a response:
- Sending emails and SMS
- Processing uploaded images or videos
- Generating PDF reports
- Calling external APIs
- Sending webhooks
- Syncing data to third-party services
Once you start using queues, you will find yourself reaching for them constantly. They are one of the best tools in Laravel.




