Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Requests from two of my amazon nodes going into same backend node. I'm trying to figure out why?

By Googling I found that "hashing is done using class-C network address of the client address"

Can anybody explain me algorithm behind ip_hash, if possible with some examples.

share|improve this question
up vote 4 down vote accepted

The very short answer: coincodence is why. The hashing algorithm made it end up in the same bucket, and the problem it tries to solve is "make sure that the same client always talks to the same backend - yet still try to keep a fairly even spread across my backends".

It's equivilent to other IP-hashing algorithms. On a very basic level:

  1. You look at the IP-address of the peer contacting you.
  2. You hash it - doing this gives you a fairly random number (yet, always the same for the same address) - more random than the IP-address, which depending on your users can be very sequential.
  3. Pick a backend by doing hash % backends

What you accomplish by doing this, is a fairly even spread of your clients - yet you should be able to expect that the clients keep talk to the same backend for every request. This is very useful if you have session-data stored on each server, for example.

If you just want to spread the load across your backend, and don't have anything to worry about as far as your application goes; Round Robin is a better option - you'll get a more even spread (even though in most cases just marginally - ip_hash works great) - and it will consume slightly less resources due to not spending time hashing the client address.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.