1 Definition and purpose

1.1 Meaning of IP hash

IP hash is a load balancing technique that selects a backend server by applying a hash function to a client’s IP address. The resulting value is used to assign the request to one server in a pool. Under stable conditions, the same address tends to produce the same destination, making the method deterministic and predictable.

1.2 Role in load balancing

In load balancing, IP hash is used to distribute traffic while also preserving a degree of session continuity. It is especially useful when applications benefit from requests from the same client being handled by the same backend instance. This can reduce the need for shared session storage or application-side routing logic.

1.3 Comparison with other routing methods

Unlike round-robin load balancing, which cycles through servers in sequence, IP hash ties routing to a client attribute. This can improve session affinity but may reduce evenness in traffic distribution. Compared with cookie-based persistence, it does not require client-side state. Compared with least-connections methods, it is simpler and less adaptive to live server load.

2 How IP hash works

2.1 Client IP extraction

The load balancer first identifies the source IP address associated with the incoming request. In direct connections, this is usually straightforward. In proxy chains or forwarded setups, the device may need to inspect forwarding headers or connection metadata to determine the address to use.

2.2 Hash calculation

After extracting the address, the system applies a hashing algorithm to convert it into a numeric value. The algorithm is designed to produce a repeatable output for the same input. Different implementations may use different hash functions or incorporate additional routing rules.

2.3 Server selection

The hash output is mapped onto the available backend servers, often by taking the result modulo the number of active nodes or by using a similar lookup method. The chosen server receives the request. If the server pool changes, the mapping may also change depending on the implementation.

2.4 Consistency of mapping

A defining feature of IP hash is that repeated requests from the same client address usually go to the same backend server. This consistency is valuable for applications that maintain state locally. However, the stability of the mapping depends on the server set remaining relatively unchanged and on the client address staying the same.

3 Implementation considerations

3.1 Hashing algorithms

Implementations may use simple arithmetic mapping, standard hash functions, or more specialized schemes. The choice affects distribution quality, speed, and stability when servers are added or removed. A stronger hash can reduce clustering, though the overall design still depends on the size and composition of the backend pool.

3.2 IPv4 and IPv6 handling

Both IPv4 and IPv6 addresses can be used as hash inputs, but they differ in length and representation. Systems must normalize address formats so that equivalent client identities are handled consistently. IPv6, with its larger address space, may reduce accidental collisions but does not remove routing concentration caused by shared prefixes or privacy features.

3.3 Proxy and NAT effects

Network address translation and intermediary proxies can cause many clients to appear under the same source IP. In such cases, the hash may direct a large volume of traffic to one backend server. This can be especially noticeable in corporate networks, mobile carriers, and shared public gateways.

3.4 Changes in server pools

Adding or removing backends can disrupt the mapping between clients and servers. In basic IP hash schemes, many clients may be reassigned when the pool changes. More advanced implementations may reduce disruption, but perfect stability is difficult to maintain when the set of available servers is dynamic.

4 Advantages

4.1 Session persistence

IP hash can help preserve session affinity without storing session identifiers in cookies. This is useful for applications that keep user state in memory or on local disk. By consistently routing a client to the same backend, it can reduce the complexity of session management.

4.2 Simplicity of configuration

The method is relatively easy to set up. Administrators often need only define a backend group and enable IP-based routing rules. Because the logic is deterministic, it is straightforward to understand and troubleshoot in smaller deployments.

4.3 Low processing overhead

Compared with schemes that inspect application content or maintain detailed connection histories, IP hash requires limited computation. The load balancer only needs to examine the client address and apply a mapping rule. This makes it suitable for high-throughput environments where routing efficiency matters.

5 Limitations

5.1 Uneven traffic distribution

IP hash does not guarantee equal load across servers. If a few source addresses generate many requests, those requests may cluster on a small number of backends. As a result, one server can become busier than others even when the overall client count appears balanced.

5.2 Shared IP address issues

When many users share one public address, they may all be assigned to the same backend server. This can happen behind large NAT devices or carrier gateways. The effect can reduce scalability and create hotspots unrelated to actual user demand.

5.3 Mobility and address changes

Clients whose IP addresses change frequently may lose session continuity. This is common with mobile networks, roaming users, and some dynamic broadband connections. If the address changes, the hash result may point to a different backend, interrupting in-memory session state.

5.4 Impact of backend failures

If a selected server becomes unavailable, requests that would normally go to it must be rerouted. Depending on the system design, this can break persistence or shift many clients to other nodes. Recovery behavior varies across implementations and may affect user experience.

6 Common use cases

6.1 Web session affinity

IP hash is often used for web applications that store session data locally on the application server. It helps keep a user’s requests aligned with one backend, reducing the need for shared session databases or external caches. This approach is especially common in simpler application architectures.

6.2 Reverse proxies

Reverse proxies may use IP hash to distribute incoming traffic among application servers. In this role, the proxy acts as the routing layer and applies the hashing rule before forwarding requests. The method is common where deterministic assignment is preferred over dynamic load awareness.

6.3 Application gateways

Application gateways sometimes use IP-based routing to maintain continuity for clients interacting with stateful services. The gateway can direct traffic consistently while keeping the backend layer abstracted from the client. This arrangement is useful in environments that prioritize straightforward request handling.

6.4 Stateless service routing

Although IP hash is often associated with stateful sessions, it can also be used with stateless services when operators want repeatable routing behavior. For example, it may help keep related traffic patterns stable during testing, logging, or caching. In such cases, persistence is a routing convenience rather than a functional requirement.

7.1 Sticky sessions

Sticky sessions are a broader form of session affinity in which repeated requests from a client are directed to the same backend. IP hash is one method used to achieve this behavior. Other sticky-session approaches may rely on cookies or connection metadata.

7.2 Consistent hashing

Consistent hashing is a distribution technique designed to minimize remapping when nodes are added or removed. It is often discussed alongside IP hash because both use hash-based assignment. Consistent hashing usually offers better stability in changing server pools.

7.3 Round-robin load balancing

Round-robin load balancing sends requests to servers in a fixed rotating order. It is simple and can produce fair distribution over time, but it does not preserve client-to-server affinity. IP hash trades some balance for repeatable routing.

7.4 Source IP affinity

Source IP affinity refers to routing decisions based on the originating address of a request. IP hash is a specific implementation of this idea. The term may also describe related mechanisms in network hardware and proxy software.