I can see that stateful protocols lead to less botched together 'emulated state' like cookies.
but testing becomes a lot harder to ensure that your implementation is correct and reconnects, and session continuations can be very hard to handle.
Is it considered better practice to always use stateless protocols, or is it really domain specific?
I think that authentication becomes easier when dealing with stateful protocols, but are there any other reasons you should use a stateful protocol?
The following are some advantages of statelessness: As the server does not need to manage any session, deploying the services to any number of servers is possible, and so scalability will never be a problem. No states equals less complexity; no session (state) synchronize logic to handle at the server side.
A Stateless app is an application program that does not save client data generated in one session for use in the next session with that client. A Stateful application saves data about each client session and uses that data the next time the client makes a request.
Stateless Protocol is a network protocol in which Client send request to the server and server response back as per the given state. Stateful Protocol is a network protocol in which if client send a request to the server then it expects some kind of response, in case of no response then it resend the request.
HTTP is called as a stateless protocol because each request is executed independently, without any knowledge of the requests that were executed before it, which means once the transaction ends the connection between the browser and the server is also lost.
Advantages of stateless:
How important is state to your application? Do you need a constant flow of data between different machines or is it more useful to have bursts? If you're writing an IP Telephony type application then you're probably going to want something fairly stateful, if you can get away with stateless it's likely to be cheaper and easier to do it that way. Doing things statefully is necessarily more fragile because if either end of the connection gets dropped or the connection itself goes down you run a higher risk of data loss, whereas with a stateless connection you are more likely just to have to wait for a while and try again.
They really are different tools for different jobs, but given the ease and ubiquity of stateless technologies online it's logical to look in that direction when you have the option.
I would consider it domain specific. If you're writing the moral equivalent of ping, a stateless protocol is the right choice. On the other hand, if you are writing a VNC, stateful is surely the way to go.
As for when to choose which, there are two points to bear in mind. First, while the implementation choices are either/or, the problem space is a continuum. All real world tasks have at least a little state, the question is how much and is the overhead of passing it around worth the hassle of tracking it at both ends. And second, you are generally dealing with a protocol stack, not a single protocol; making sure that everything lives at the right level can simplify things enormously.
A stateless protocol is easier to cluster since state never needs to be transfered from 1 server to another upon subsequent requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With