Statelessness Part 1
Principles of Service Orientation series continues with this first part piece on Statelessness
I’ve hinted at the importance of statelessness in the Loose Coupling piece, and here we’ll look more deeply at what state is and its impact on project success. State is one of the most difficult types of coupling to avoid because it is so common in computer systems.
What is State?
State is the current configuration and settings of a system at a given point in time. When I put my laptop down on the table it remains there until I move it; it maintains state. When I save this document I am writing it stays that way until I work on it next; it too retains state. On a more technical level, when I set a variable to a value my code now has state. State is a natural concept for software developers; one they learn early on. The fact that state is constant in all our human activities probably exacerbates the issue.
Back to my previous shopping cart example, the cart itself is a stateful construct. Adding or removing items to the cart is changing its state. When multiple operations are part of a single task they share state in that the task is only complete when all the operations happen. Most often these operations must be in a specific order, they have temporal state, and the operations must share data to accomplish their task. This is a type of dependency; each operation depends on the operations before it. This data and order are part of the state of the task. The more operations and data are shared the more state there is, and the management of such operations becomes cumbersome.
Anytime two or more operations (meaning requests) are conjoined as a single unit of work (or are required to perform a single task) state is necessarily involved. This is because the requests are related and someone has to pay a cost for correlating them; that is for matching the first request with the second.
Many developers who came of age (in the programming sense) during the Client Server era have state mentality deeply ingrained and will fall back on it when tackling newer problems; despite the fact that modern tools and technologies are designed for a different approach. This is a dangerous path into stateful, tightly-coupled code.
Why is State Expensive?
So what is wrong with all this? Why is state bad? State is bad because it increases complication. State involves several parts moving in unison in order to work correctly. The separate operations must be coordinated and the progress tracked (normally on both the client and the server); this is most often done through the use of Sessions. Sessions are conduits through which this data passes as well as the mechanism for connecting separate operations into the single task. Any time you open a database connection, or even a terminal screen, is a session. Sessions must do a lot of coordination in order to facilitate the work being performed. They must match multiple requests from the client to the appropriate session in progress (normally a specific thread of execution). Most frameworks do this for us, but as we scale these sessions become more cumbersome. The reason for this is that a

