The Master Worker Pattern
In the master worker pattern, a single master breaks a problem into many tasks and a pool of workers pulls those tasks and runs them. It is one of the most common ways to spread work across cores or machines because the workers are interchangeable.
The master holds a queue of pending tasks. Each worker repeatedly takes a task, processes it, returns the result, and asks for the next. Because workers grab tasks as they free up, the load balances itself naturally, with fast workers simply doing more tasks.
- Master Splits work, hands out tasks, and collects results.
- Workers Identical units that pull, process, and report back.
- Dynamic balancing Idle workers pull more, so uneven task sizes even out.
This self balancing is the key advantage over statically dividing work up front. If one task is unexpectedly heavy, only the worker running it is delayed, while the others keep draining the queue.
The risk is the master becoming a bottleneck or a single point of failure. If every task must pass through one coordinator, the master can saturate. Designs often shard the queue, batch task handouts, or replicate the master to relieve that pressure.
Key idea
A master hands tasks from a queue to interchangeable workers that pull as they free up, balancing load dynamically while the master risks becoming a bottleneck.