An online shop runs its web tier on 20 identical servers behind a load balancer. Today each server keeps login sessions in its own memory, so users are logged out whenever the load balancer sends them to a different server or a server restarts during a deploy. Design a shared session store. The shop has 4 million daily users, up to 1.5 million signed-in sessions at once, and the web tier handles 8,000 requests per second at peak; every request looks up its session.
Functional requirements
Create a session at login and return an opaque session ID in a cookie
Look up the session on every request from any web server
Expire idle sessions after 30 minutes and all sessions after 7 days
Log a user out everywhere by deleting their sessions
Non-functional requirements
Session lookups add under 5 ms to a request
Deploys and single node failures do not log users out
Session IDs cannot be guessed or forged
Constraints and scale
8,000 requests per second at peak, each reading a session
1.5 million concurrent sessions of about 2 KB each
Web servers are replaced on every deploy, several times a day
You will practise
Move state out of the web tier so any instance can serve any request
Use an in-memory store with TTLs and replication for fast, resilient lookups
Weigh server-side sessions against self-contained signed tokens
Show 2 hints
1.5 million sessions of 2 KB is about 3 GB. Where does that fit comfortably?
What should happen to a request if the session store is briefly unreachable?