🔴 Laravel Intermediate

What are Jobs and Queues in Laravel?

Why Interviewers Ask This

This tests whether you can apply Laravel knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

Jobs represent units of work that can be queued for asynchronous background processing. Create: php artisan make:job SendWelcomeEmail. The handle() method contains the job logic. Implement ShouldQueue to queue it; without it, it runs synchronously. Dispatch: SendWelcomeEmail::dispatch($user). Dispatch with delay: ::dispatch()->delay(now()->addMinutes(5)). Specify queue: ::dispatch()->onQueue("emails"). Set maximum tries: public int $tries = 3. Set timeout: public int $timeout = 60. On failure (after all retries): public function failed(Throwable $e) method is called. Process a specific queue: php artisan queue:work --queue=emails,default. Use Laravel Horizon for a Redis-powered queue dashboard.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Laravel answers easy to follow.