StateFull vs. StateLess

31 בAugust 2014

.StateFull and StateLess are about Computers Architecture and Design Patter

.There is a large scale of concepts around this terminology

But in other point of view it is daily used when we are coding

In origin the terminology is token from a computer or more specifically an Program

,like the Web model there is about architecture like MVC, HTTP, ASP etc

.But we can face it almost in every step at our coding

In present, computer programs are about user friendship as much as we can

.This is generally came with statefull condition where we talking on it

:But statefull isn’t only on a program it could be relevant in every small function

private int DoActionStateFull(int param)


       int innerState = param;

       innerState += 5;

       return innerState;


private int DoActionStateLess(int param)


       return param + 5 ;


,Both function are definitely identical, but, there is major different

The first one is much more readable in case of complex logic, but also easy to debug and


In the other side we have unnecessary variant in the memory, and longer code

And longer code is always i hard to debug

.This is a Trade of

Holding a state meaning reduce the efficiency, (storing every step), but it is also user friendly

.since users can restore the operations using what we called Caching

For another demo lets try a small unit in the application , commonly used in setting, .configuration parts in programs

.Imagine settings screen with three dropdown lists

.In the first, the profileName, in the second the selected area at specific application

.And in the third a collors pallet to configure this area

,Now all this date is stored in DB


.Well , user can configure a color region in the application

Now what will happens when change the selected User

Than by default the application load the selected user last settings from the DB and last changes

.will be lost

But if this screen are holding a state , than until we press the save button of screen like that the Data wouldn’t serialize into DB, and we will have the option to configure all settings for several .users and Caching the data along runtime

Using state machine Pattern it is not must the have a State, because in a giving some condition , the state will be change but all possible states are well defined in origin

Basic service are usually stateless, like one plus one are two no matter outer conditions, but dynamic services, are depends on specific users , or specific settings. Meaning the application

.holds a state about the client. And this state in depends on verity of elements

StateFull could be dangerous with multiThreading programing, since if we get a second call the inner state is not relevant to the new client, or in other case the new client state rewriting the

.older state while the former process of the former client isn’t finish yet

Therefor develop and debug stateFull programs is more expensive and required better design

.but it is commonly required in moddern application

הוסף תגובה
facebook linkedin twitter email

Leave a Reply

Your email address will not be published. Required fields are marked *