According to GROWTHEOLOGY, statelessness is the property of protocols and applications to treat each interaction as a separate, self-contained process. In contrast, stateful systems need to store session data.
Web applications, cloud systems and other client-server architectures can either be stateful or stateless. Choosing the right method is crucial because both concepts have their advantages and disadvantages.
What is a state?
In computer science, the term “state” describes the status, the specific conditions of a system or an object at a certain point in time. States describe the context in which a process or a request is executed.
Several work steps are often necessary to complete a task. Each work step leads to a change in the state of the processing system. Depending on the status of the processing, other actions must be carried out in the further course of the process.
A simple example should clarify this:
A user wants to convert a JPG file to PNG using an online image converter. The website requires a login so that the user is initially in the “not logged in” state. He logs in, which changes his status to “logged in”.
The user has already used this service and adjusted some presets for the desired compression parameters. Now he uploads the file, whereupon the converter converts the image depending on the specified options. Both the login status and the various parameters are examples of states.
Stateful and stateless logs
The above example shows a stateful process. In such systems, the individual processing steps depend on previous processes. Stateful processes are not synonymous with stateful protocols. The HTTP web protocol is basically stateless. Each request-response pair is self-contained and does not require any temporarily stored information. Nevertheless, web applications like the online converter described can be set up.
In the case of state-based protocols, the server combines several requests into one session. It saves information about previous transactions – so-called session data. He accesses these in the further course of the session so that they do not have to be retransmitted. It is also possible to save information over several sessions.
A typical example of state-oriented protocols is FTP (File Transfer Protocol). If a client connects to an FTP server, the server opens a session that remains active until communication has ended. During the session, the server remembers various information – including the transmission parameters and the current directory on the server.
With stateless protocols, however, the server does not store any session data. Stateless means that every request is a completely new process that takes place completely independently of previous processes. Each request contains all the data necessary to process the request. Stateful processes can be implemented at a higher level of communication, for example with URL parameters, cookies or POST data.
Statelessness and state liability in comparison
Stateful web services require a more complex server infrastructure. You need storage systems and databases to hold session data for the clients. Programming is also complicated .
With each request, the server must check whether the request is valid and meaningful in the context of the current session. In addition, he must regularly clean up incomplete or canceled sessions. Stateful services are useful for small, simple systems that generate little dynamic data.
Stateless systems have a correspondingly simpler structure. They provide a high level of scalability through better load distribution. All requests are complete in themselves and independent of all previous processes, so that they can easily be delegated to other servers. In addition, there is a higher fault tolerance. Incompatible requests, incomplete session data or disconnections are not a problem.