IP hash is a load balancing algorithm that uses a hash function on the client's source IP address to determine which backend server will handle the request. This creates a deterministic, sticky mapping, ensuring all requests from that specific IP are sent to the same server for the duration of a session. It is a form of session persistence that simplifies state management for applications where user session data is stored locally on a server.
Glossary
IP Hash

What is IP Hash?
IP hash is a deterministic load balancing method used to ensure session persistence by mapping client requests to specific servers.
The algorithm calculates a hash value from the client's IP address, often combined with the port number, and uses modulo arithmetic against the number of available healthy servers. While effective for sticky sessions, it can cause uneven load distribution if client IPs are not uniformly distributed, such as when traffic originates from a few large network gateways. It is commonly implemented in Layer 4 (transport layer) load balancers and is a foundational technique within broader consistent hashing schemes used in distributed systems.
Key Features of IP Hash
IP Hash is a deterministic, session-aware load balancing method that uses a hash of the client's source IP address to assign requests to backend servers. This ensures consistent routing for a given client.
Deterministic Session Persistence
IP Hash provides session persistence (sticky sessions) by guaranteeing that all requests from a specific client IP are routed to the same backend server for the duration of a session. This is critical for stateful applications where user session data is stored locally on a server.
- Mechanism: A hash function (e.g., MD5, SHA-1) is applied to the client's source IP address.
- Output: The hash output maps to a specific server in the pool.
- Result: The same client IP always produces the same hash, directing it to the same server.
Example: An e-commerce shopping cart application relies on IP Hash to ensure a user's cart items, stored in a server's local memory, remain accessible throughout their browsing session.
Stateless Load Balancer Operation
Unlike methods that track server connection counts, IP Hash enables the load balancer itself to remain stateless. The routing decision is made anew for each request based solely on the client IP, simplifying the load balancer's logic and reducing its memory footprint.
- No Session Table: The load balancer does not need to maintain a lookup table of client-to-server mappings.
- Pure Calculation: Each request is independently evaluated using the hash function.
- Scalability: This statelessness allows the load balancer to handle massive connection rates efficiently, as it performs a simple computation per request.
Handling of IP Address Changes & Asymmetry
A significant limitation of IP Hash is its vulnerability to changes in the client's apparent IP address. This can lead to broken sessions and is a key consideration for deployment.
Common Causes of IP Change:
- Mobile Networks: A user switching from cellular to Wi-Fi.
- Corporate NAT/PROXY Pools: Outbound requests from a large organization may rotate through multiple public IPs.
- Load Balancer Chains: If traffic passes through multiple tiers of load balancers, the source IP seen by the final balancer may be the previous balancer's IP.
Consequence: The hash input changes, routing the client to a different server, which likely lacks their session state, causing errors.
Uneven Traffic Distribution
IP Hash can lead to skewed load distribution across servers, as it depends on the randomness of incoming IP addresses. It does not account for server load or capacity.
Scenarios Causing Imbalance:
- Geographic Concentration: A large number of requests originating from a single corporate network (sharing a public IP) will all hash to the same server, overloading it.
- Non-Uniform Hash Ranges: Even with a good hash function, real-world IP address distribution is not perfectly uniform, leading to some servers receiving more traffic.
- Static Server Pool: The algorithm does not dynamically adjust for servers with different processing capabilities (unlike Weighted Least Connections).
Mitigation: Using a consistent hashing variant can improve distribution when servers are added or removed.
Configuration and Tuning Parameters
Implementing IP Hash involves configuring specific parameters on the load balancer to control its behavior and resilience.
Key Parameters:
- Hash Function: Choice of algorithm (e.g.,
src_ip,src_ip+port,src_ip+dst_ip+port). Using source port can help differentiate multiple connections from the same NAT device. - Server Weight: Some implementations (e.g., NGINX's
ip_hash) support weighted IP hash, where server weights are considered in the hash distribution. - Failover Behavior: Definition of what happens when the target server is unhealthy. Typically, the hash is recalculated (using a modulus) to find the next available server, breaking session persistence.
Example NGINX Directive:
nginxupstream backend { ip_hash; server backend1.example.com weight=3; server backend2.example.com; }
Use Cases vs. Alternatives
IP Hash is a specialized tool. Understanding when to use it versus other algorithms is crucial for system design.
Ideal for:
- Legacy Stateful Applications: Where session data cannot be easily externalized to a shared cache or database.
- Simple Persistence Needs: Environments with stable client IPs (e.g., internal corporate VPN access).
- Computational Efficiency: When the load balancer must make ultra-fast routing decisions with minimal overhead.
Consider Alternatives When:
- Client IPs are Unstable: Use cookie-based persistence (e.g.,
app_cookie,insert_cookie) for web applications. - Server Load Varies: Use Least Connections or Least Response Time for optimal resource utilization.
- Dynamic Infrastructure: Use Consistent Hashing to minimize reshuffling when servers are added/removed frequently.
- Geographic Routing: Use Latency-Based Routing or GeoDNS to direct users to the nearest data center.
IP Hash vs. Other Load Balancing Algorithms
A technical comparison of key characteristics between IP Hash and other common load balancing algorithms, focusing on their behavior in heterogeneous fleet orchestration and dynamic task allocation scenarios.
| Feature / Metric | IP Hash | Round Robin / Weighted Round Robin | Least Connections / Weighted Least Connections | Least Response Time |
|---|---|---|---|---|
Primary Routing Determinant | Hash of client source IP address | Sequential order in server list | Current active connection count | Combined metric of active connections and latency |
Session Persistence Guarantee | High (for consistent client IP) | None | None | None |
Traffic Distribution Evenness | Deterministic but can be uneven with few client IPs | Perfectly even (or weighted) | Dynamic, aims for even load | Dynamic, aims for optimal performance |
Handling of Server State Changes (Add/Remove) | Poor (causes major hash ring reshuffle, breaking persistence) | Good (seamlessly integrates new servers into rotation) | Good (new connections distributed based on updated counts) | Good (new connections use updated metrics) |
Algorithmic Complexity & Overhead | Low (simple hash calculation) | Very Low (increment pointer) | Medium (requires tracking and comparing connection counts) | High (requires active latency probing and connection tracking) |
Ideal Use Case | Stateful applications requiring session stickiness (e.g., shopping carts, real-time control sessions for specific robots) | Stateless services, homogeneous server pools (e.g., API endpoints, sensor data ingestion) | Long-lived connections, variable server capacities (e.g., WebSocket streams, file transfers) | Latency-sensitive applications with variable backend performance (e.g., user-facing APIs, real-time dashboards) |
Impact on Fleet Health & Battery-Aware Scheduling | Low adaptability; may route to an unhealthy or low-battery agent if its IP is hashed | High adaptability when combined with health checks | High adaptability; naturally avoids overloaded or struggling agents | Highest adaptability; actively routes to the most performant agent |
Support for Dynamic Task Priority | None (routing is IP-bound, not task-bound) | Indirect (via server weighting) | Indirect (via connection weighting) | Indirect (latency may reflect current load from high-priority tasks) |
Frequently Asked Questions
IP hash is a deterministic load balancing algorithm used to distribute client requests across a server pool. These questions address its core mechanics, use cases, and trade-offs within modern distributed systems and fleet orchestration.
IP hash is a deterministic load balancing algorithm that uses a hash function on the client's source IP address to determine which backend server will handle its requests. The algorithm takes the client's IP address (IPv4 or IPv6), applies a hash function (like MD5 or a simple modulo operation), and maps the resulting value to a specific server in the pool. This ensures that all requests from the same client IP are consistently routed to the same server for the duration of the session, providing session persistence without requiring server-side state sharing. For example, a request from 192.168.1.100 might hash to server index 2, guaranteeing it always reaches that server while the pool membership remains stable.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
IP Hash is one of several deterministic and dynamic algorithms used to distribute workload. These related terms define the core strategies for routing traffic and managing server pools.
Consistent Hashing
A distributed hashing technique that maps both servers and requests onto a hash ring. When a server is added or removed, only a small fraction of keys need to be remapped, minimizing disruption. This is critical for distributed caches and storage systems where session persistence is required but server pools are dynamic.
- Key Benefit: Provides stability during scaling events.
- Use Case: Foundation for systems like Apache Cassandra and DynamoDB.
Session Persistence (Sticky Sessions)
A method where a load balancer directs all requests from a specific client session to the same backend server. This is often implemented using a cookie injected by the load balancer. While IP Hash provides a form of session persistence, dedicated sticky session mechanisms are more robust for clients behind proxies or NATs where IP addresses change.
- Mechanism: Cookie-based, SSL session ID, or custom header.
- Trade-off: Can lead to uneven load if sessions are long-lived.
Least Connections
A dynamic load balancing algorithm that directs a new request to the server with the fewest active connections at that moment. This is more responsive to real-time server load than static algorithms like Round Robin or IP Hash.
- Advantage: Efficiently accounts for varying request complexity and server capacity.
- Implementation: Requires the load balancer to maintain a real-time count of active connections to each backend.
Health Check
A periodic test performed by a load balancer to verify a server instance is operational and capable of accepting traffic. Active health checks send synthetic requests, while passive health checks monitor the response to real client traffic. This is a foundational capability for any production load balancer to ensure traffic is only sent to healthy nodes.
- Types: TCP connect, HTTP GET, custom script.
- Critical Parameters: Check interval, timeout, success/failure thresholds.
Circuit Breaker Pattern
A software design pattern used to detect failures and prevent an application from repeatedly trying to execute an operation that is likely to fail. In load balancing, this pattern can be implemented to temporarily stop sending traffic to a failing backend, allowing it time to recover.
- States: Closed (normal), Open (failing), Half-Open (probing for recovery).
- Purpose: Prevents cascading failures and enables graceful degradation.
Layer 7 Load Balancing
Operates at the application layer (HTTP/HTTPS) of the OSI model. Makes routing decisions based on the content of the message, such as URLs, HTTP headers, cookies, or the message body. This enables advanced routing like content-based routing and API version routing, which are not possible with IP Hash (a Layer 3/4 technique).
- Capabilities: SSL termination, path-based routing, header manipulation.
- Example Systems: NGINX, HAProxy, AWS Application Load Balancer.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us