Backend Engineering
brian | Published: Feb. 27, 2024, 11:57 a.m. | Updated: July 12, 2025, 12:30 a.m.
Stateful
A system is described as Stateful if it is designed to remember preceding(existing) events or user interactions;[1] the remembered information is called the state of the system. In a stateful system, the server remembers information about you, it remembers your previous interactions with the server which is known as a state, and it includes things such as: user authentication, preferences, session data, recent activities, etc.
Pros: More personalized user experience
Cons: More complex
Stateful Backend
1. user logins
2. backend talks with database to verify the login credentials
3. database responds to the backend and it will generate a session id
4.backend stores the session id locally, and returns the session id back to the user as a cookie to the browser so it can store it locally aswell.
Now when the user visits the page again, it will send this "cookie", (which contains the session id ) in every subsequent request to validate the user.
Stateful Protocol TCP
TCP is a stateful protocol because It maintains state information about active connections between communicating endpoints. This state information includes details such as sequence numbers, acknowledgment numbers, window sizes, and connection status. UDP on the other hand is stateless
Stateless
Stateless: in a stateless system, the server does NOT remember previous interactions, and each request is independenent from any previous requests. HTTP is stateless by nature because each HTTP request is independenent from the previous
Pros: easy to implement
cons: limited user personalization
Stateless Backends
* stateless backends can store data elsewhere like a database
*backend is stateless, but the system is stateful
1. Login, generate an id session, then the session is stored in the database
2. Every time the client refreshes, the backend will check the database to see if the session is valid