We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Core Fundamentals
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Core Fundamentals
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
, the protocol that powers the entire web, has a fundamental design constraint that shapes everything we build: it's stateless. Every single request is independent. The server has no built-in memory of who you are or what you did 2 seconds ago.
Think about that. You log into Amazon. You add a laptop to your cart. You navigate to checkout. From HTTP's perspective, those are three completely unrelated requests from a stranger on the internet. The server has zero inherent reason to connect them.
So how does Amazon know you're logged in? How does it remember your cart? How does it know that the person clicking "Place Order" is the same person who logged in 10 minutes ago?
Session management. It's the set of techniques that give the illusion of continuity on top of a fundamentally amnesiac protocol. Every time you stay logged in, every shopping cart that persists across pages, every "remember me" checkbox, that's session management at work.
And getting it wrong has real consequences. In 2012, GitHub had a mass account hijack because of a session management vulnerability. Attackers could forge session cookies and take over any account. Session management isn't just a feature, it's a security boundary.
The oldest and most proven approach to session management uses server-side sessions with cookies. Here's how it works.
abc123def456) and stores it as the key for that session objectSet-Cookie header: session_id=abc123def456The cookie only contains a random ID, not your username, role, or any real data. This is intentional.
If the cookie contained user=admin&role=superuser, anyone could edit their cookie to user=admin&role=superuser and become admin. By storing only a random, unguessable session ID, the actual data stays on the server where users can't tamper with it.
Cookies have several flags that control their security:
| Flag | What It Does | Why It Matters |
|---|---|---|
HttpOnly | JavaScript cannot read the cookie | Prevents XSS attacks from stealing session IDs |
Secure | Cookie only sent over | Prevents session IDs from being intercepted on public Wi-Fi |
SameSite=Strict | Cookie not sent on cross-site requests | Prevents CSRF attacks |
Max-Age | Cookie expires after N seconds | Sessions don't live forever |
A properly configured session cookie looks like:
Set-Cookie: session_id=abc123def456; HttpOnly; Secure; SameSite=Strict; Max-Age=86400; Path=/