Performance: Job chaining and batching
This affects how background jobs are processed, impacting server load and response time for queued tasks.
Jump into concepts and practice - no test required
JobA::withChain([
new JobB(),
new JobC(),
])->dispatch();dispatch(new JobA()); dispatch(new JobB()); dispatch(new JobC());
| Pattern | Queue Dispatches | Worker Wake-ups | Processing Overhead | Verdict |
|---|---|---|---|---|
| Individual dispatch per job | N | N | High due to repeated overhead | [X] Bad |
| Job chaining for dependent jobs | 1 | 1 per job in chain | Moderate, sequential processing | [!] OK |
| Batching many independent jobs | 1 | Optimized worker usage | Low overhead, parallel processing | [OK] Good |
job chaining and job batching in Laravel?JobA and JobB in Laravel?dispatch(new JobA)->chain([new JobB]).dispatch(new JobA)->chain([new JobB]); matches the correct syntax with dispatch(new JobA)->chain([new JobB]);.Bus::batch([
new Job1(),
new Job2(),
new Job3()
])->then(function () {
Log::info('Batch completed successfully');
})->dispatch();then() callback runs after all jobs in the batch succeed.dispatch(new JobA)->chain(new JobB);
chain() method requires an array of job instances.new JobB without wrapping it in an array.JobX, JobY, and JobZ where JobY should only run after JobX completes, but JobZ can run anytime in parallel. Which Laravel approach correctly handles this?