Stateless Services: The State Is Out There
The only problem with that is that the state doesn't really go away. Stateless services just suffer from NIMBYism ("Not in my back yard") when it comes to state. A stateless service needs to be stateful when it performs it action and since the state is not there, it has to get it from somewhere.
Stateless services are da bomb right? They are easy to scale (since they have no state, you can deploy as many as you like), they are easy to reuse (no state, no baggage), and what not.
The only problem with that is that the state doesn't really go away. Stateless services just suffer from NIMBYism ("Not in my back yard") when it comes to state. A stateless service needs to be stateful when it performs it action and since the state is not there, it has to get it from somewhere.
- You need to pay network tax for getting the state (remember the fallacies of distributed computing..).
- If that someone else is a single source (such as a database) it can easily become a barrier for scalability. (I wrote about the RDBMS problem in the RDBMS is dead.) If it isn't a single source you need to go to multiple sources so you have the network problem multiplies.
- You need to pay network tax for putting the state back at the state repository.
The other way to get the state is to put the state on the message -- the "document" approach. This approach is superior to the previous one as you get to piggyback the data on the request. This is a good example of stateless communications* which, as a side effect, can save the stateless service the problems mentioned above.
The "state on the message" approach works when the handling of messages is serialized. For instance, only one "station" in the flow can make changes to the state at any one time. Unfortunately this only works for a subset of the interactions you can have. In most cases multiple consumers need to get to the same data or coordinate
You can also combine the two approaches and sometimes get good reults.Another way altogether is to look at stateful services which I'll talk about in the next post.
* Many times people fail to make the distinction between stateless services and stateless communications. I'll expand on that in another post.

