When your Laravel application grows, some tasks take more time like sending emails, generating PDF reports, importing Excel files, or resizing images. If you run these tasks directly inside the controller, your page will become slow.
Laravel Queues help by sending heavy tasks to the background, so your user gets a fast response.
In this blog, I explain queues step-by-step with a proper example using Database Queue.
Step 1 — Set Queue Driver
Open .env file:
Laravel will now store jobs inside your database.
Step 2 — Create Queue Jobs Table
Run:
This creates a jobs table that stores all pending background jobs.
Step 3 — Create a Job Class
Example: send a welcome email in the background.
Open the job file:
This job will send an email in the background.
Step 4 — Dispatch the Job from Controller
Inside your controller:
Now the controller is fast because the email task is queued.
Step 5 — Run Queue Worker
To process queued jobs, you must run:
This worker keeps checking the jobs table and runs pending tasks.
Step 6 — Test the Example
Register a new user
You will receive JSON response instantly
Email will be sent in background by the queue worker
You can check jobs and failed_jobs tables for debugging.
Step 7 — Running Queues in Production (Important)
On live server, queue worker must run 24/7.
Use Supervisor:
Supervisor ensures your queue always stays active even after server restart.
When to Use Queues
You should use queues for:
Sending emails
Creating invoices
Generating large PDF reports
Resizing/uploading images
Importing/Exporting Excel files
Sending notifications
Third-party API calls
SMS sending
Video processing
Anything slow → send to queue.