IP Hash and Source IP Hash in Load Balanching: Detailed Explained
Overview – IP Hash
IP Hash and Source IP Hash are load balancing algorithms that use the client’s IP address as a key to determine which server should handle a given request. These methods ensure that requests from the same client are consistently directed to the same server, maintaining session persistence. This can be particularly useful for applications where it is important to maintain a continuous session state across multiple requests from the same client.
IP Hash Algorithm
IP Hash is a load balancing technique where the load balancer uses a hash function to map the client’s IP address to a specific server. The hash function takes the client’s IP address as input and produces an output that determines the selected server. This method ensures that requests from the same client are consistently routed to the same server.

How It Works
- Client IP Address: The client sends a request to the load balancer.
- Hash Calculation: The load balancer applies a hash function to the client’s IP address.
- Server Selection: The result of the hash function is used to select one of the available servers.
- Request Routing: The load balancer routes the request to the selected server.
- Session Persistence: Subsequent requests from the same client IP address will produce the same hash result, ensuring they are directed to the same server.
Detailed Example
Assume we have three servers (Server A, Server B, and Server C) and a simple hash function that maps IP addresses to these servers. Let’s say the client’s IP address is 10.1.1.1.
- Hash Calculation: The hash function applied to 10.1.1.1 might produce a value that maps to Server A.
- Request Routing: The load balancer directs the request to Server A.
- Subsequent Requests: Any further requests from 10.1.1.1 will be routed to Server A, ensuring session persistence.
Advantages
- Session Persistence: Maintains session state by consistently routing requests from the same client to the same server.
- Simplicity: Easy to implement and understand.
Disadvantages
- Imbalance Risk: If many clients have IP addresses that hash to the same server, it can lead to an uneven distribution of the load.
- Lack of Adaptability: Does not adapt well to changes in server availability or capacity without rehashing.
Source IP Hash Algorithm
Source IP Hash is a variation of the IP Hash algorithm that specifically uses the source IP address of the client to determine the server. This method ensures that requests from the same source IP address are consistently directed to the same server, similar to the basic IP Hash method but with a focus on the source IP address.
How It Works
- Source IP Address: The client sends a request to the load balancer.
- Hash Calculation: The load balancer uses the source IP address to calculate a hash.
- Server Selection: The hash result is used to select a server from the pool.
- Request Routing: The load balancer routes the request to the selected server based on the hash result.
- Session Persistence: Subsequent requests from the same source IP address will be directed to the same server.
Detailed Example
Consider a load balancer with three servers (Server A, Server B, and Server C) and a hash function that maps source IP addresses to these servers. Suppose a client’s source IP address is 10.1.1.1.
- Hash Calculation: The hash function applied to 10.1.1.1 produces a value that maps to Server B.
- Request Routing: The load balancer routes the request to Server B.
- Subsequent Requests: Further requests from 10.1.1.1 will be consistently routed to Server B, ensuring session persistence.
Advantages
- Session Persistence: Ensures that requests from the same source IP address are routed to the same server, maintaining session state.
- Consistency: Provides consistent routing based on the source IP address, which can be beneficial for certain applications.
Disadvantages
- Imbalance Risk: Similar to the basic IP Hash, there is a risk of load imbalance if many clients’ source IP addresses hash to the same server.
- Not Adaptable: Does not easily adapt to changes in the server pool without recalculating hashes for the entire set of IP addresses.
Summary
IP Hash and Source IP Hash are load balancing algorithms that use the client’s IP address to determine the server for routing requests. Both methods provide session persistence by ensuring that requests from the same IP address are consistently directed to the same server. This can be particularly useful for maintaining session state in applications where clients need to interact with the same server across multiple requests.
While these methods offer simplicity and consistency, they also come with potential disadvantages, such as the risk of load imbalance and lack of adaptability to changes in server availability or capacity. To mitigate these issues, careful consideration must be given to the hash function used and the distribution of IP addresses among the client base.
Useful Links
https://www.a10networks.com/products
https://sanchitgurukul.com/tutorials-cat
IP Hash and Source IP Hash in Load Balanching: Detailed Explained
This article provided insights on the topic. For latest updates and detailed guides, stay connected with Sanchit Gurukul.
