Skip to main content
Cloud / DevOpsTraffic & ScalingDiagramBeginner

Sticky Session

KO: 스티키 세션·EN: Sticky Session·JA: スティッキーセッション

A load balancing technique (session affinity) that pins all subsequent requests from a given user to the same backend server using cookies or client IP hashing

Table of Contents

Structure Diagram

Sticky Session (Session Affinity) vs Stateless Shared Store
StickySticky Session

Pinned to 1 host · Local state

  • Load BalanceUneven load if heavy users cluster
  • On Host FailureLocal session lost; user logged out
  • Auto ScalingHarder scale-in & rolling drain
StatelessStateless + Redis/JWT

Any node handles any request

  • Load BalanceEven distribution across all nodes
  • On Host FailureSeamless failover via shared store
  • Auto ScalingEffortless scale-out, scale-in & rollout
Quick Answer

What is Sticky Session?

A load balancing technique (session affinity) that pins all subsequent requests from a given user to the same backend server using cookies or client IP hashing. It is a core concept in Traffic & Scaling within Cloud / DevOps.

Core Principles

Sticky Sessions (Session Affinity) instruct a load balancer to route all subsequent requests from the same user to the exact same backend server that handled their first request, typically tracked via a load-balancer cookie or client IP hash.

While useful for lifting legacy stateful apps behind a load balancer or improving local cache hit rates, sticky sessions undermine even traffic distribution and cause session loss whenever a pinned host crashes or scales in.

Practical Takeaways

  • Prefer stateless services with external stores: For new cloud-native apps, externalize session state into Redis or signed tokens (JWT) so any instance can serve any request and autoscaling remains frictionless.
  • Use cookie-based affinity over IP hashing: Corporate firewalls and mobile carrier NATs put thousands of users behind one public IP, causing severe hot spots under IP-based stickiness.
  • Know valid exceptions: Sticky sessions remain practical for WebSocket upgrade handshakes (e.g., Socket.IO polling) and workloads that benefit from warm local in-memory caches.

Notable Examples

  • AWS Application Load Balancer: Supports duration-based (AWSALB) and application-cookie stickiness per target group.
  • Socket.IO Multi-Node Clusters: Requires sticky sessions during initial HTTP polling handshake before upgrading to WebSockets.
  • NGINX hash / sticky cookie: Provides lightweight session affinity at the reverse proxy layer.