dev-resources.site
for different kinds of informations.
Random is a great load balancing policy
Random is a great load-balancing policy
I have an unpopular opinion regarding load-balancing policies. Random selection is usually good enough. π
I work on many network-based applications, from custom service meshes to payments-based routing, and when we start thinking about routing or load distribution, load balancing policies are mentioned.
Most of the time, I recommend starting with a Random selection policy. π²
People often struggle with this statement. They want to optimize using more complex policies like least-connection or round-robin.
But in the quest to optimize, are you adding more complexity than is required?
The least-connection policy works by routing new connections to the service with the least current connections. This same approach could also be used with transactions, but to implement this, you need to implement a tracker that maintains connection or transaction status and distribution. π
Round-robin works by selecting the next service in a list and looping through it. Itβs simple, but you need to maintain a position within the list. βΎοΈ
Both approaches can become very complicated when you want to coordinate across multiple instances of the load-balancing system (donβt do that).
Random is simple. Maintain a list, and pick from that list randomly. There is no need or value in coordinating across instances; every instance is its own independent implementation.
Simple, straightforward, and reliable. πͺ
Thatβs not to say that policies like round-robin or least-connection are not beneficial. They can benefit use cases that need them.
However, many use cases donβt need a complex load-balancing algorithm.
A random policy is often effective at distributing load and reducing the complexity of an application.
Like many things in technology, start with something simple initially and then optimize as needed. β¨
Featured ones: