What is Laravel's job batching?
Why Interviewers Ask This
This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.
Answer
Job batching (Laravel 8+) allows dispatching multiple queued jobs and executing callbacks when all jobs in the batch have completed, or when any job fails. Create a batch: Bus::batch([new ProcessVideo(1), new ProcessVideo(2), new ProcessVideo(3)])->then(fn($batch) => $this->notifyComplete())->catch(fn($batch, $e) => $this->notifyFailure($e))->finally(fn($batch) => $this->cleanup())->dispatch(). Batches are stored in the job_batches table. Monitor progress: $batch->totalJobs, $batch->processedJobs(), $batch->failedJobs, $batch->progress(). Cancel a batch: $batch->cancel(). Jobs can add more jobs to the batch from within: $this->batch()->add([new NextJob()]). Allow partial failure: ->allowFailures(). Batching is ideal for processing large datasets in parallel with completion notifications.
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.