DEV Community

BillyGoat12
BillyGoat12

Posted on

Stateful and Stateless protocol

What is protocol?

Protocol is known as "A set of rules that you have to follow". When a computer wants to send data to another computer they also must follow a protocol. Technically we can send data between computers without protocol but it would not be effective and may have collisions. Think of a classroom full of English speaking kids all learning math from a Spanish speaking teacher. This is an example of how not following protocols can lower the efficiency of the kids ability to learn and this can also happen in data transfer affecting our database ability to read data. Now think of a classroom with everyone speaking, no one would be able to get their point across and this would be an example of collision and this can happen when two devices are sending data at the same time.

Stateful Protocol

Now that we know the importance of protocol let's talk about stateful protocol. Stateful protocol is defined as "If client send a request to the server then it expects some kind of response, if it does not get any response then it resend the request." So basically if you login using a certain credentials it will be pass into the server and the server will pass that into the database and the database will verify that password match the username. Then the server will store some kind of variable(key) saying that the client is okay and pass it to the client. Now everytime the client communicates with the server, the server will check if the client variable(key) matches the server variable(key) and store the data in the server. The protocol taken in a stateful server will cause "a tight dependency between server and client". So if the client tries to switch server or if the server crash their credentials would not match nor was their session recorded in this new server causing them to restart the whole process again on the new server.

Alt Text

Stateless protocol

Now that we understand stateful servers let's talk about stateless servers. stateless server is when the “client sends a request to the server and server response back according to current state. It does not require the server to retain session information or a status about each communicating partner for multiple requests”. So basically just like stateless expect the database store the sessions and the variable(key) not the server. The protocol taken in a stateless server "there is no tight dependency between server and client". This means if your server crashes or if you switch server you will be able to still access your session.

Alt Text

conclusion

In conclusion the difference is where the sessions and verification variable is being stored at. In stateful protocol it will be stored in the server and in stateless it will be stored in the database. Because of this difference stateful will not handle crashes of servers better then stateless. On the other hand if your application needs better security then stateful is the way to go because stateful takes in the state of the connection causing it to be more strict.

Top comments (0)