Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are stateless protocols considered better to use over stateful protocols?

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?

like image 720
Brian R. Bondy Avatar asked Mar 09 '09 16:03

Brian R. Bondy


People also ask

What are the advantages of stateless 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.

Which application is ideal for stateless or stateful?

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.

What makes a protocol stateful or stateless?

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.

Why is HTTP known as a stateless protocol write advantages and disadvantages of the stateless protocol?

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.


4 Answers

Advantages of stateless:

  1. High scalability (you can can send request to any node, you can add nodes at any time)
  2. High availability (if one node fails, there is no state that is lost, just resend request to another node)
  3. High speed (as there is no state, results are cacheable)
like image 90
vartec Avatar answered Oct 14 '22 00:10

vartec


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.

like image 25
glenatron Avatar answered Oct 13 '22 22:10

glenatron


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.

like image 25
MarkusQ Avatar answered Oct 13 '22 23:10

MarkusQ


A stateless protocol is easier to cluster since state never needs to be transfered from 1 server to another upon subsequent requests.

like image 20
Allain Lalonde Avatar answered Oct 14 '22 00:10

Allain Lalonde