DEV Community

Benjamin Cane
Benjamin Cane

Posted on • Originally published at itnext.io on

Random is a great load balancing policy

Random is a great load-balancing policy


Image generated by AI

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. ✨


Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

Use Playwright to test. Use Playwright to monitor.

Join Vercel, CrowdStrike, and thousands of other teams that run end-to-end monitors on Checkly's programmable monitoring platform.

Get started now!

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay