Live data from Hacker News

When Simple Wins: Power of 2 Load Balancing

fly.io

1–10 of 49 posts

Re: When Simple Wins: Power of 2 Load Balancing

#3
The simplest load balancing I've done is modulo the user ID by the number of servers then point at that server.

This solves caching too since you are only ever receiving and caching user data on a single server. No cache communication required. You can enforce it on the server side for security as well.

Doesn't require a load balance server - just an extra line of code.

Keep it simple.

Re: When Simple Wins: Power of 2 Load Balancing

#4

The simplest load balancing I've done is modulo the user ID by the number of servers then point at that server. This solves caching too since you are only ever receiving and caching user data on a single server. No cache communication required. You can enforce it on the server side for security as well. Doesn't require a load balance server - just an extra line of code. Keep it simple.

This is how many horizontally scalable OLTP databases operate too (e.g. DynamoDB, Citus): picking a partition key, then deterministically routing work associated with that partition key to the proper, well, partition.

Re: When Simple Wins: Power of 2 Load Balancing

#5

The simplest load balancing I've done is modulo the user ID by the number of servers then point at that server. This solves caching too since you are only ever receiving and caching user data on a single server. No cache communication required. You can enforce it on the server side for security as well. Doesn't require a load balance server - just an extra line of code. Keep it simple.

But where is the modulo being calculated?

Re: When Simple Wins: Power of 2 Load Balancing

#6

The simplest load balancing I've done is modulo the user ID by the number of servers then point at that server. This solves caching too since you are only ever receiving and caching user data on a single server. No cache communication required. You can enforce it on the server side for security as well. Doesn't require a load balance server - just an extra line of code. Keep it simple.

But where is the modulo being calculated?

[removed, brain failure]

Re: When Simple Wins: Power of 2 Load Balancing

#7

The simplest load balancing I've done is modulo the user ID by the number of servers then point at that server. This solves caching too since you are only ever receiving and caching user data on a single server. No cache communication required. You can enforce it on the server side for security as well. Doesn't require a load balance server - just an extra line of code. Keep it simple.

What happens when the number of servers changes? The cache hit rate would likely drop to zero until it warms up again, which is a good way to accidentally overload your systems.

Load balancing based on consistent hashing is the better way to implement this.

Re: When Simple Wins: Power of 2 Load Balancing

#8

Earlier quoted context omitted.

But where is the modulo being calculated?

[removed, brain failure]

In the original comment, user mentions that the modulo logic would not require a loadbalancer server. So, I would assume what the user meant is that you do not require a high throughput loadbalancer. But you still need some entity to do the modulo work as well as health-checking servers to calculate modulo for active servers only.

Re: When Simple Wins: Power of 2 Load Balancing

#9
"Power of 2 Random Choices" ... has nothing to do with the "Power of 2" directly.

I like 2Choice because it is not dependent on hash function design & is temporal, but I have a positive aversion to the 2^n hash distributions when it comes to data, specifically for distributed systems which need to flex up/down [1].

[1] - http://notmysock.org/blog/hacks/1440

Post reply on HN