Laravel interview question · Most asked

How do queues work in Laravel?

Summary

A job class implementing ShouldQueue is serialised and pushed to a queue backend (Redis, database, SQS, Beanstalkd). Worker processes (php artisan queue:work) pop jobs and run their handle method, retrying on failure and moving jobs that keep failing to the failed_jobs table.

Longer Answer

Dispatching (ProcessPodcast::dispatch($podcast)) stores the job payload. Eloquent models are serialised as their IDs (SerializesModels) and re-fetched when the job runs, so the job sees current data (or fails if the row is gone).

Workers are long-running PHP processes managed by Supervisor or systemd (or Horizon for Redis). Key options: queue names and priorities (--queue=high,default), --tries, --backoff, --timeout, --max-jobs / --max-time to recycle workers, and --memory.

Because workers are long-lived, they keep code and static state in memory: restart them on deploy (queue:restart) and avoid state leaking between jobs. The sync driver runs jobs inline, useful in tests and local development.

Key Points

  • Jobs are serialised; models by ID.
  • Long-running workers under a supervisor.
  • Tries, backoff, timeout, failed_jobs.
  • Restart workers on deploy.

Deep dive: Queues & Background Processing in Depth

Explanation

What interviewers look for

Operational understanding: supervisors, restarts, failure handling, and that workers are long-lived processes.

Follow-up questions

  • What happens to a job if the worker is killed mid-job?
  • How do you prioritise some jobs over others?

More most-asked Laravel questions

← All Laravel questions