Session Persistence & Sticky Sessions 00:00:01 A logged-in shopper loses the cart on the next request Three shop servers keep sessions only in their own memory. Follow a shopper's second request to a different server and predict whether that worker recognizes the login. Client A logs in on Server 1, which keeps the session in memory. Clients B and C go to the next two servers. The next turn is Server 1. It has no session for B. The routing policy and session location are coupled. If the application depends on local state, changing destinations can lose continuity even when every server is healthy. 00:00:34 A cookie remembers one destination Give each browser a routing cookie after its first visit. Two shoppers share a home router but use different browsers. Trace why they can still be placed separately. Client A has no cookie. Server 2 is the least busy. The response carries SERVERID for Server 2, signed so it cannot be changed. Every request from A goes to Server 2. B and C get their own cookies, even if all three share one IP address. Integrity-protect affinity information and keep authentication separate. A server label tells the balancer where to route, and cannot establish who the shopper is. 00:01:14 A network change moves the shopper Replace the cookie with a rule based on source address. Watch several people behind one router, then move a phone from Wi-Fi to a mobile network mid-session. Client A's address always gives Server 3. B and C sit behind one router. They share an address and so a server. Client A leaves Wi-Fi. The new address gives Server 2, which has no session. Address affinity can concentrate many users on one backend and can change when a user moves networks. Its simplicity comes with weak alignment to actual user identity. 00:01:51 Let a second worker find the same session Move session records into a shared store with a defined lifetime. The shopper's next request lands on a different worker. Follow how that worker reconstructs the session. The session is written to the store with an expiry. Server 2 reads the same session. Nothing is lost. Requests continue on Server 2 with the session intact. Shared state eases placement and recovery while adding a dependency with its own latency, durability and availability requirements. Define behavior for expiry and concurrent session updates. 00:02:25 The preferred worker fails during checkout A signed routing cookie still points to a worker that health checks have removed. Predict what selecting a new healthy destination can recover from the old worker's memory. Client A is tied to Server 2. Health checks fail. Everything in its memory is gone. The balancer picks Server 3 and sets a new cookie. A stays with Server 3. Moving back would break the session a second time. Routing away can restore reachability. Durable cart contents or completed orders need separately stored authority, and resuming an action must respect any side effect already committed.