Stateless Architecture is entirely different and better than Stateful. Stateless applications scale very poorly. When the volume of concurrent users grow in size in Stateful applications, more servers run the applications added, and load distributed evenly between those servers using a load-balancer. Stateless and Stateful – Different behavior in application side. I have researched how stateful and stateless BSP application are handled in ABAP server side. In this blog I will explain how stateful and stateless BSP application behave differently. Click fire button, and we can find in stateless application, these two requests are.
A stateful app is one that stores information about what has happened or changed since it started running. Any public info about what 'mode' it is in, or how many records is has processed, or whatever, makes it stateful.
Stateless apps don't expose any of that information. They give the same response to the same request, function or method call, every time. HTTP is stateless in its raw form - if you do a GET to a particular URL, you get (theoretically) the same response every time. The exception of course is when we start adding statefulness on top, e.g. with ASP.NET web apps :) But if you think of a static website with only HTML files and images, you'll know what I mean.
a stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of requests and responses. A stateless protocol does not require the server to retain session information or status about each communications partner for the duration of multiple requests. In contrast, a protocol which requires the keeping of internal state is known as a stateful protocol.
Web services invoked over HTTP protocol are stateless by design. When the request reaches the Web server, the ASP.NET runtime manages the request by instantiating an instance of your Web service type, deserializing the SOAP envelope XML stream, and invoking the requested method passing parameters if applicable. A new instance of the Web service type is created for each HTTP request targeting the service, so any information stored in data fields contained within the type are recreated for each round trip. If you want to persist state you must specifically enable state for the method as shown here:
This will cause the ASP.NET runtime to create an HttpSessionState object the first time a method that has session state enabled is called. Each subsequent call to a method that has session enabled will share the same session state object, so long as the client passes a session cookie with each subsequent request. If the client does not pass a session cookie ASP.NET will create a new session for each call.
The client invoking the service must be session aware, something we take for granted when we navigate Web sites with a browser. The client proxy created for a .NET Web service includes a CookieContainer property, and .NET provides us with CookieContainer type that we can instantiate and assign the proxy as follows:
// create cookie container once for the duration of the session
System.Net.CookieContainer cookies = newSystem.Net.CookieContainer();
// each time invoking the service, assign the same cookie container before invoking methods
localhost.SessionService1 svc = newlocalhost.SessionService1();
svc.CookieContainer = cookies;
MessageBox.Show(svc.UpdateHitCounter());
When the proxy invokes the service, it serializes the method call into a SOAP envelope, and builds an HTTP request with appropriate headers, and posts to the endpoint URI of the Web service. The HTTP headers will include the session cookie if one is provided here, and that's how ASP.NET can find the right session state object to make it available to your Web method.
Stateless apps don't expose any of that information. They give the same response to the same request, function or method call, every time. HTTP is stateless in its raw form - if you do a GET to a particular URL, you get (theoretically) the same response every time. The exception of course is when we start adding statefulness on top, e.g. with ASP.NET web apps :) But if you think of a static website with only HTML files and images, you'll know what I mean.
a stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of requests and responses. A stateless protocol does not require the server to retain session information or status about each communications partner for the duration of multiple requests. In contrast, a protocol which requires the keeping of internal state is known as a stateful protocol.
Web services invoked over HTTP protocol are stateless by design. When the request reaches the Web server, the ASP.NET runtime manages the request by instantiating an instance of your Web service type, deserializing the SOAP envelope XML stream, and invoking the requested method passing parameters if applicable. A new instance of the Web service type is created for each HTTP request targeting the service, so any information stored in data fields contained within the type are recreated for each round trip. If you want to persist state you must specifically enable state for the method as shown here:
This will cause the ASP.NET runtime to create an HttpSessionState object the first time a method that has session state enabled is called. Each subsequent call to a method that has session enabled will share the same session state object, so long as the client passes a session cookie with each subsequent request. If the client does not pass a session cookie ASP.NET will create a new session for each call.
The client invoking the service must be session aware, something we take for granted when we navigate Web sites with a browser. The client proxy created for a .NET Web service includes a CookieContainer property, and .NET provides us with CookieContainer type that we can instantiate and assign the proxy as follows:
// create cookie container once for the duration of the session
System.Net.CookieContainer cookies = newSystem.Net.CookieContainer();
// each time invoking the service, assign the same cookie container before invoking methods
localhost.SessionService1 svc = newlocalhost.SessionService1();
svc.CookieContainer = cookies;
MessageBox.Show(svc.UpdateHitCounter());
When the proxy invokes the service, it serializes the method call into a SOAP envelope, and builds an HTTP request with appropriate headers, and posts to the endpoint URI of the Web service. The HTTP headers will include the session cookie if one is provided here, and that's how ASP.NET can find the right session state object to make it available to your Web method.
I'm interested in articles which have some concrete information about stateless and stateful design in programming. I'm interested because I want to learn more about it, but I really can't find any good articles about it. I've read dozens of articles on the web which vaguely discuss the subject, or they're talking about web servers and sessions - which are also 'bout stateful vs stateless, but I'm interested in stateless vs stateful design of attributes in coding. Example: I've heard that BL-classes are stateless by design, entity classes (or atleast that's what I call them - like Person(id, name, ..)) are stateful, etc.
I think it's important to know, because I believe if I can understand it, I can write better code (e.g. granularity in mind).
Anyways, really short, here's what I know 'bout stateful vs stateless:
Stateful (like WinForms): Stores the data for further use, but limits the scalability of an application, because it's limited by CPU or memory limits
Stateless (Like ASP.NET - although ASP tries to be stateful with ViewStates):After actions are completed, the data gets transfered, and the instance gets handed back to the thread pool (Amorphous).
As you can see, it's pretty vague and limited information (and quite focussed on server interaction), so I'd be really grateful if you could provide me with some more tasty bits of information :)
Asad Saeeduddin38.3k55 gold badges6565 silver badges110110 bronze badges
Team-JoKiTeam-JoKi80622 gold badges1010 silver badges2323 bronze badges
8 Answers
I suggest that you start from a question in StackOverflow that discusses the advantages of stateless programming. This is more in the context of functional programming, but what you will read also applies in other programming paradigms.
Stateless programming is related to the mathematical notion of a function, which when called with the same arguments, always return the same results. This is a key concept of the functional programming paradigm and I expect that you will be able to find many relevant articles in that area.
Another area that you could research in order to gain more understanding is RESTful web services. These are by design 'stateless', in contrast to other web technologies that try to somehow keep state. (In fact what you say that ASP.NET is stateless isn't correct - ASP.NET tries hard to keep state using ViewState and are definitely to be characterized as stateful. ASP.NET MVC on the other hand is a stateless technology). There are many places that discuss 'statelessness' of RESTful web services (like this blog spot), but you could again start from an SO question.
Community♦
kgiannakakiskgiannakakis89.3k2323 gold badges147147 silver badges186186 bronze badges
A stateful app is one that stores information about what has happened or changed since it started running. Any public info about what 'mode' it is in, or how many records is has processed, or whatever, makes it stateful.
Stateless apps don't expose any of that information. They give the same response to the same request, function or method call, every time. HTTP is stateless in its raw form - if you do a GET to a particular URL, you get (theoretically) the same response every time. The exception of course is when we start adding statefulness on top, e.g. with ASP.NET web apps :) But if you think of a static website with only HTML files and images, you'll know what I mean.
Lucas Wilson-RichterLucas Wilson-Richter
Stateless means there is no memory of the past. Every transaction is performed as if it were being done for the very first time.
Stateful means that there is memory of the past. Previous transactions are remembered and may affect the current transaction.
Stateless:
Stateful:
Refer from:https://softwareengineering.stackexchange.com/questions/101337/whats-the-difference-between-stateful-and-stateless
Esteban Verbel32811 gold badge1111 silver badges2929 bronze badges
AnkitAnkit3,92111 gold badge1515 silver badges1414 bronze badges
The adjective Stateful or Stateless refers only to the state of the conversation, it is not in connection with the concept of function which provides the same output for the same input. If so any dynamic web application (with a database behind it) would be a stateful service, which is obviously false. With this in mind if I entrust the task to keep conversational state in the underlying technology (such as a coockie or http session) I'm implementing a stateful service, but if all the necessary information (the context) are passed as parameters I'm implementing a stateless service.It should be noted that even if the passed parameter is an 'identifier' of the conversational state (e.g. a ticket or a sessionId) we are still operating under a stateless service, because the conversation is stateless (the ticket is continually passed between client and server), and are the two endpoints to be, so to speak, 'stateful'.
MarcoMarco
Money transfered online form one account to another account is stateful, because the receving account has information about the sender.Handing over cash from a person to another person, this transaction is statless, because after cash is recived the identity of the giver is not there with the cash.
S Upendra raoS Upendra rao
Just to add on others' contributions....Another way is look at it from a web server and concurrency's point of view...
HTTP is stateless in nature for a reason...In the case of a web server, being stateful means that it would have to remember a user's 'state' for their last connection, and /or keep an open connection to a requester. That would be very expensive and 'stressful' in an application with thousands of concurrent connections...
Being stateless in this case has obvious efficient usage of resources...i.e support a connection in in a single instance of request and response...No overhead of keeping connections open and/or remember anything from the last request...
Ken.FukiziKen.Fukizi
We make Webapps statefull by overriding HTTP stateless behaviour by using session objects.When we use session objets state is carried but we still use HTTP only.
feel good and programmingfeel good and programming65122 gold badges1010 silver badges2424 bronze badges
I had the same doubt about stateful v/s stateless class design and did some research. Just completed and my findings has been posted in my blog
- Entity classes needs to be stateful
- The helper / worker classes should not be stateful.
Joy George KunjikkuruJoy George Kunjikkuru