Laravel interview question · Most asked

Explain $tries, $backoff, $timeout and retry_after for Laravel jobs. How do they interact?

Summary

$tries is how many attempts a job gets, $backoff how long to wait between attempts, $timeout how long one attempt may run before the worker kills it, and the connection's retry_after how long the queue waits before assuming a job was lost and handing it out again.

Longer Answer

retry_after (in config/queue.php) must be longer than the longest job $timeout. If it is shorter, the queue releases a job that is still running, and a second worker runs it concurrently: duplicate emails, double charges.

  • $backoff can be an array for exponential backoff: [10, 60, 300].
  • retryUntil() sets a deadline instead of a count.
  • $maxExceptions stops retrying after N unhandled exceptions even if releases are allowed.
  • failed(Throwable $e) runs after the final failure, for alerts or compensation.
  • $this->release(30) puts the job back deliberately (for example when rate-limited) and counts as an attempt.

Since any job can run more than once, jobs must be idempotent.

Key Points

  • retry_after must exceed $timeout.
  • Backoff arrays give exponential delays.
  • failed() for final-failure handling.
  • Every job may run twice: make it idempotent.

Deep dive: Queues & Background Processing in Depth

Explanation

What interviewers look for

The retry_after versus timeout interaction. Candidates who have debugged duplicate job execution know it.

Follow-up questions

  • How would you make a 'charge customer' job idempotent?

More most-asked Laravel questions

← All Laravel questions