Interview frequency: …
Short answer
Define middleware() in the Job class and use tools such as WithoutOverlapping or ThrottlesExceptions to avoid blocking external accounts.
Explanation
When calling external APIs with strict Rate Limits (such as Twitter API), running 50 workers at once can immediately get your account blocked. Job Middleware can intercept a job before handle(), delay it or automatically return it to the queue when it exceeds the allowed rate, or prevent two jobs from modifying the same record with WithoutOverlapping.
Code example
public function middleware(): array {
return [
(new WithoutOverlapping($this->user->id))->releaseAfter(60),
new RateLimited('external-api'),
];
}Common mistakes
- Writing throttling logic manually inside handle() and calling sleep(), which freezes the entire Worker process.
Follow-up questions
- How do Job Chaining and Job Batching differ in Laravel?
- How do Queues work in Laravel, and what is the purpose of the ShouldQueue interface?