Break horizontal scaling with in-memory session state
Task
Run a stateful application behind a load balancer and watch users lose their sessions, then fix it twice -- once with sticky sessions and once by moving state out -- and record what each fix costs.
Steps
- Run a small application that stores a counter in memory per session, behind a load balancer with three instances and round-robin distribution.
- Drive a client that makes 30 sequential requests with the same session cookie and records the counter each time. Save to
lab/sessions.txtand note how often the count resets. - Enable sticky sessions and repeat. Record the result, then kill the instance the client is pinned to and record what happens to that user.
- Move session state to a shared store container. Repeat the 30 requests, then kill an instance mid-run and record whether the session survived.
- Write in
lab/sessions.mdthe cost of each approach: what sticky sessions do to load distribution, and what dependency the shared store introduces.
Verify
grep -Ec 'reset|1$' lab/sessions.txt
grep -Eci 'sticky' lab/sessions.md
grep -Eci 'shared store|external|survived' lab/sessions.md
grep -Eci 'uneven|distribution|dependency' lab/sessions.md
The notes must record a cost for BOTH fixes. Sticky sessions are a crutch with a price, and the shared store puts a new component on the critical path.
This is an independent study companion for CompTIA Cloud+ CV0-004 and is not produced by or endorsed by CompTIA.