Difiniation – IP Hashing Persistence
IP hashing persistence is a method used by load balancers to ensure that all requests from the same client are consistently directed to the same backend server, based on the hash value of the client’s IP address. This technique is particularly useful in environments where session data needs to be preserved across multiple requests, and it’s favoured for its simplicity and effectiveness without the need for client-side tracking mechanisms like cookies.
How IP Hashing Persistence Works
Step-by-Step Process:
- Hash Function: The load balancer uses a hash function to convert the source IP address of an incoming request into a numerical value. This hash function is designed to distribute IP addresses evenly across the available servers.
- Server Selection: The hash value is then used to select a backend server. Typically, this is achieved by taking the hash value modulo the number of servers in the pool. For example, if there are 5 servers, the server index could be calculated as hash(IP) % 5. This ensures that the same IP address always maps to the same server unless the number of servers changes.
- Request Routing: All requests from the same IP address will consistently be routed to the same server, as long as the server pool configuration remains unchanged.
- Session Continuity: This persistence ensures that any session-specific data stored on a server remains accessible to the user across multiple interactions, as all their requests will consistently be directed to the same server.

Example: Online Gaming Server
Scenario: Consider a multiplayer online gaming platform where players connect to game servers that maintain game state and player progress during a session.
Step 1: Player Connection
- John connects to the gaming platform from his home network. His IP address is 192.168.1.100.
- He initiates a connection to join a game.
Step 2: Hash Function Application
- The load balancer receives the request and applies a hash function to John’s IP address. Let’s say the hash function outputs the value 12345.
Step 3: Server Selection
- Assume there are 4 game servers available. The load balancer calculates the server index as 12345 % 4, which equals 1.
- Therefore, John’s requests are directed to Server B (since servers are typically indexed starting from 0).
Step 4: Continuous Gameplay
- During his gaming session, John might make multiple requests to the server to update his game state, score, or player interactions.
- Each time, the load balancer applies the same hash function to his IP address and routes the requests to Server B.
- This ensures that all of John’s game state and progress are continuously updated and maintained on the same server throughout his session.
Conclusion
- John enjoys a seamless gaming experience without any disruption to his game state or loss of progress, because all his requests are consistently handled by Server B.
Benefits and Considerations – IP Hashing Persistence
Benefits:
- Simplicity: No need to track sessions using cookies or session IDs.
- Transparency: Completely transparent to clients; no client configuration is required.
- Stability: As long as the client’s IP and the server pool remain the same, the client will always be routed to the same server.
Considerations:
- Dynamic IP Addresses: If a client’s IP address changes (due to changing networks or dynamic IP allocation), they will lose their session continuity.
- Scalability: Changes in the number of servers (such as adding or removing servers) will disrupt the distribution pattern, potentially causing clients to be reassigned to different servers.
- Load Distribution: Not all IPs will necessarily distribute evenly across servers, which can lead to potential load imbalances if certain IP ranges generate more traffic.
This explanation and example illustrate how IP hashing can be an effective persistence strategy for maintaining session continuity, particularly in applications where client-side tracking is not feasible or desired.
Useful Links
https://sanchitgurukul.com/proxy
https://sanchitgurukul.com/load-balancer
