Break horizontal scaling with in-memory session state

short · 45 min · Objective 3.1

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

  1. Run a small application that stores a counter in memory per session, behind a load balancer with three instances and round-robin distribution.
  2. Drive a client that makes 30 sequential requests with the same session cookie and records the counter each time. Save to lab/sessions.txt and note how often the count resets.
  3. Enable sticky sessions and repeat. Record the result, then kill the instance the client is pinned to and record what happens to that user.
  4. Move session state to a shared store container. Repeat the 30 requests, then kill an instance mid-run and record whether the session survived.
  5. Write in lab/sessions.md the 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.