Question
Why is HTTP called a "stateless" protocol?
Answer
Each HTTP request is independent and self-contained, so the server keeps no memory of previous requests.
After sending a response, the server has no memory of the client. Each request-response cycle is complete in itself. This means the server can't naturally track:
- Which user is making requests
- What they did in previous requests
- Shopping cart contents, login status, etc.
Cookies and sessions were invented to work around this limitation.
Note saved — thanks!
Question
What are cookies and how do they work?
Answer
Cookies are key-value pairs the browser stores and automatically resends with every request to the same domain.
How they work:
- Server sets a cookie via
Set-Cookieheader in response - Browser stores the cookie
- Browser sends cookie with every subsequent request to that domain
- Server can read the cookie values
Cookies persist across requests and browser sessions (until they expire), enabling stateful behavior over stateless HTTP.
Go deeper:
Using HTTP cookies (MDN) — the canonical reference on Set-Cookie, the Cookie header, and lifetime/security attributes.
HTTP cookie (Wikipedia) — origin of the name, cookie types, and the privacy/security landscape.
Note saved — thanks!