Channels ▼

Arnon Rotem-Gal-Oz

Dr. Dobb's Bloggers

Stateless Services: The State Is Out There

May 17, 2008

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.

There are basically two approaches to getting the state into the stateless service. The common way is to make the state someone else's problem (usually that would spell a database). With this approach, the stateless service perform queries (database or otherwise) to get the state from the third party. This is problematic in many ways; for example:.
  • 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.



Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.