शब्दकोश · क्लाउड और होस्टिंग

Session Affinity

Session affinity, or sticky sessions, makes a load balancer send all requests from one client to the same backend server.

अपडेट: अक्टूबर 21, 2026

Session affinity is a load-balancing mode that pins a client to one backend instance, usually by setting a cookie or hashing the client's IP address. Every later request in that session goes to the same server.

Why it matters

Applications that keep login or cart state in server memory break when a request reaches a different server. Affinity is a quick workaround. Its costs are uneven load, since busy users stay on busy servers, and weaker failover, because when the pinned server dies its sessions are lost unless state is stored elsewhere. The sturdier fix is to keep session data in a shared store such as a database or cache so any server can handle any request.

Example

An nginx upstream using IP-hash affinity:

upstream app {
    ip_hash;
    server 10.0.0.11;
    server 10.0.0.12;
}

Clients behind one corporate NAT share an IP and all land on the same server, skewing the load. Cookie-based affinity is more precise. Check what your load balancer sets with the cookie checker.

Common mistakes

  • Using IP hash and overloading a server when many users share one NAT address.
  • Forgetting that draining a node does not move pinned users until their sessions end.
  • Treating affinity as a substitute for shared session storage.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.