API Fundamentals Course
API Fundamentals
/
Intermediate

Sessions

Definition

A server-side data store that temporarily holds information about a specific user's interaction with the application, linked to the user via a Session ID stored in a client-side cookie.

Explain Like I'm New

Cookies hold very little data (4KB limit) and can be tampered with. So, the server creates a 'Folder' on its own hard drive for you, puts all your data in it (Shopping Cart, Auth Status), and gives the folder a random serial number. It hands you a Cookie containing ONLY that serial number. This is a Session.

Real World Example

Logging into a bank. The bank server creates a Session in its memory. If the bank detects suspicious activity, they simply delete the Session from their memory. Your cookie still exists, but the serial number now points to a deleted folder, instantly locking you out.

Common Use Cases

  • •Authentication
  • •Shopping carts
  • •Multi-step wizards

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Where is the actual user data (like their email or cart items) stored in Session-based architecture?

intermediate

  • Why are Sessions considered 'Stateful' architecture?

Flash Cards

Question

Where is data stored?

Click to reveal answer
Answer

On the Server (in memory, in a database, or in a fast cache like Redis). Only the meaningless Session ID is stored on the client's browser.

Question

Why Stateful?

Click to reveal answer
Answer

Because the Server has to maintain a 'state' (a memory) of who is logged in. If the server crashes and loses its memory, every single user is instantly logged out. (This is why JWTs, which are stateless, were invented).