Skip to content

Sticky Session

Medium — good to knowNetworking

ELI5 — The Vibe Check

Sticky sessions make sure a user always gets routed to the SAME server, like getting the same cashier every time you visit a store. It's needed when your app stores session data in memory on one server. The downside: if that server goes down, the user's session is gone.

Real Talk

Sticky sessions (session persistence or session affinity) configure a load balancer to route a client's requests to the same backend server for the duration of a session, typically using a cookie or IP hash. Required when session state is stored locally on servers rather than in a shared cache.

Show Me The Code

# Nginx sticky sessions with ip_hash
upstream backend {
  ip_hash;  # Same IP always goes to same server
  server app1.example.com;
  server app2.example.com;
}

# Better: use shared session storage instead
# Store sessions in Redis, not server memory
app.use(session({
  store: new RedisStore({ client: redisClient }),
  secret: 'your-secret'
}));

When You'll Hear This

"We need sticky sessions because the app stores state in memory." / "Replace sticky sessions with a Redis session store so any server can handle any user."

Made with passive-aggressive love by manoga.digital. Powered by Claude.