Round-robin load balancing keeps task submission simple: users send work to a manager, which chooses a worker instead of requiring users to track worker capacity or task counts. section 7.0
Use a small mental model: the manager owns an ordered worker list and remembers the index of the last selected worker. Each selection advances that index; reaching the end wraps back to zero. section 7.3.1
Listing 7.4 Implementing a naive scheduling algorithm
func (m *Manager) SelectWorker() string {
var newWorker int #1
if m.LastWorker+1 < len(m.Workers) { #2
newWorker = m.LastWorker + 1 #3
m.LastWorker++ #4
} else { #5
newWorker = 0 #6
m.LastWorker = 0 #7
}
return m.Workers[newWorker] #8
}
The nine-line Go method makes the state transition explicit: compare the previous index with the list boundary, advance or reset, then return the selected worker. section 7.3.1
A minimal implementation assigns these responsibilities:
- Store workers as address strings, commonly in <hostname>:<port> form. section 7.3.1
- Store LastWorker as an integer index into the worker slice. section 7.3.1
- Return the next worker, or return the first worker after the final entry. section 7.3.1
Three workers in rotation
Create workers at localhost:5556, localhost:5557, and localhost:5558, pass their addresses to manager.New with the "roundrobin" scheduler, and submit tasks through the manager. The manager selects the workers in sequence, cycling back to the first after the third. section 10.7
This is a deliberately naive scheduler. Unlike a score-based scheduler, it does not calculate which candidate machine is best; it follows order and retains only its position in that order. section 1.5.3


