Development › Queues
Queues
Laravel queues handle deferred work: mail, notifications, outbox publishing, CPU-heavy jobs, and retries.
#Connections
Configure via QUEUE_CONNECTION:
| Value | Use |
|---|---|
sync | Tests / simple local scripts |
database | Easy local/dev without Redis |
redis | Recommended for production workers |
#Workers
Run workers separately from the HTTP process:
php artisan queue:work --tries=3 --timeout=90In Docker, the worker service runs queue (and optionally Kafka consumer) processes. Scale horizontally:
docker compose up --scale worker=5#What belongs on a queue
- Sending emails / SMS
- Publishing outbox events to Kafka
- Generating exports/reports
- Any work that must not block the HTTP response
Keep Application Actions synchronous for the core business transaction; dispatch jobs for side effects when eventual consistency is acceptable.
#Reliability
- Make jobs idempotent where retries are possible.
- Use
--triesand failed-job handling (queue:failed). - Prefer small payloads (IDs, not large graphs).
- Set sensible timeouts; long work should be chunked.
#Scheduling
Use Laravel’s scheduler (routes/console.php / bootstrap/app.php schedule) for cron-like tasks. The scheduler should only enqueue work; workers execute it.