Stateful vs Stateless Web Tier

In this article, I will try to state what stateful and stateless web tiers are and how they are different.
When the user types a domain name then the request is sent to the Domain name system(DNS) which returns the associated IP address to the user then the request is sent to the servers of that website.
In stateful web tier, user data(state) is stored on the web server itself. Data can be the username, profile image, password, etc.

In the above figure, data for user 1 is stored in server 1. To authenticate user 1, HTTP request must be routed to server 1.
A drawback here is, if server 1 fails due to some error then it will be difficult to authenticate user 1. A solution for this can be to duplicate the data of one server on other servers but that again can be a very complex task with duplication as well updating the data.
In stateless web tier, we do not maintain the data(state) of the users on web servers. We always maintain the user data over a shared location be it a database or cache.
Even if a server fails, it will not stop user authentication for any particular user.

Shared location (Database or Cache) can be the single point of failure and to tackle that we can duplicate the databases or cache and update them regularly.



