'The application must not have state. The state should be stored in the data layer where the database "
There are projects where this is the norm, precisely called "illiterate architectures." Regardless, each architecture should be stateless, of course, doubtful, and the term itself may also open up a discussion.
Most of the "cityless" applications actually have state, but since the rule is higher than state (no pun intended), this state is stored in one global place; Database. As Peter mentions, convenience and simplification may be the reason for this, but it has also often been heard that this is for scalability . Without the state appearing anywhere, but in the database, it was easy to add additional front-end servers, processing servers, and what you have.
Despite the fact that this does have some merit, I think we need to distinguish between a temporary state and an authoritative state.
The temporary condition may be something like the place where you are in the order process, and the data that you have already entered. In Java EE, you can save this in, for example, @ConversationScoped beans, or @Stateful beans. This means that you are holding inside the web layer accordingly. business level.
The benefits of this are the ease of use, performance, and offloading of a single central database. Of course, you can also store the temporary state in your central database, but you probably want to remove this from regular, non-temporary data, which means that you need some additional programming complexity. It is also generally much faster to retrieve data from the web tier, and it removes some of the load from the database.
In many systems, there is only one primary database (a database that accepts records), so this single database can become a huge bottleneck in this setup.
Depending on your actual architecture and configuration, without storing a temporary state in the database, you may actually improve your ability to scale.
The disadvantages are that you need your client to stick to a single server on which a temporary state is currently stored. This is typically called a “sticky session”. If one server that this client interacts with fails or needs to be restarted or something else, the client will lose this temporary data. There are some schemes, such as state replication to all nodes in a cluster or to neighboring nodes (buddy replication), but this complicates the situation and can overload the network (if all nodes are constantly replicated to each other).
An authoritative state means that it represents general data, which is the only source of information. This state is something that we almost always love in a central place, but sometimes you see that it is stored in, for example, a web node.
For example, suppose we have a list of the latest prices, and instead of storing it in a central place, we save it on the Internet node where it was entered. Now there is the concept of a “one and only” node website that has this information and other servers, may begin to assume that this “only” node website exists. Adding additional nodes is now impossible, since it violates this assumption.