Serksa
All Concepts
API & Backend

Stateless vs Stateful

1

What is it?

<strong>Stateless</strong> means the server doesn't remember previous requests. <strong>Stateful</strong> means the server remembers you between requests. Most modern web APIs are stateless.

2

Think of it like...

The Forgetful vs Remembering Cashier

Stateless is like a cashier who forgets you instantly. You must show your receipt (token) each time to prove who you are.

🤷

Stateless

Forgets you after each transaction

🧠

Stateful

Remembers your order

🎫

Token

Your receipt (proof)

3

Visual Flow

📱Request 1

With token

🖥️Server

Doesn't remember

📱Request 2

Must send token again

4

Where you see it

1

Client Logs In

Server verifies credentials

2

Server Issues Token

Gives client a proof of identity

3

Client Stores Token

Saves it (in cookie or localStorage)

4

Future Requests

Client includes token in every request

5

Server Validates

Checks token, doesn't need to remember you

5

Common Mistake

Wrong

Stateless means the app can't remember anything about users

Correct

The app remembers data in the database. 'Stateless' only means the server doesn't remember the conversation between requests. The client sends proof (token) with each request.

💡 Real-World Example

REST APIs are stateless:

1

You log in → Server gives you a JWT token

2

Request 1: GET /profile (with token) → Server returns your profile

3

Request 2: POST /post (with token) → Server creates post

4

Server doesn't remember Request 1 when handling Request 2

5

Each request is independent, token proves who you are