Stateful or Stateless?

We often hear about stateful applications and how to scale your apps by ensuring it is stateless. Here is a primer if you are confused:

Stateful apps are associated with

  1. B2C (business-to-consumer) or customer-facing apps
  2. B2B (business-to-business) or background apps
State is captured as:
  • session (web tier) – cookies
  • storage (database tier) – SQL or NoSQL store is immaterial
  • request/response (logical tier)
  • transactions (RDBMS tier)

Examples of stateful apps:

  • RSS feed reader
  • ATMs (automated teller machines)
  • any app that requires data (dynamic)

Wait a minute. All but static apps require data so are you saying that all dynamic apps are stateful? That is a resounding yes.

Let me explain:

State is tied to data. No, let me rephrase that, state is data. As long as you are dealing with IPO (input -> process -> output), you are dealing with data.

Hence, stateless applications are an illusion. A comment to that post nails it:

“stateless applications are no applications, they are … ummm … static”

From the request tier, you have cookies, server sessions or whatnot (data).

In the storage tier, you process and store data.

So it is not a question of whether making your app stateful or stateless. It is about the fundamentals of computing.

Making apps stateless are supposed to make them scalable.

No matter how scalable your web tier or business logic tier is, the relational database is always the bottleneck.


Because relational databases are inherently not scalable since it does serial writes to maintain consistency. If you are thinking about scalability, think about parallelization. You can make parallel reads with RDBMS but you can only make serial writes. Writing to multi-master stores projects a semblance of scalability but in practice, it is simply redundancy to enable high-availability. You cannot scale what is inherently serial.

On the other hand, you can make parallel writes with NoSQL at the expense of consistency. NoSQL has its own various mechanism to overcome stale data.

For more on NoSQL, see the book The Architecture of Open Source Applications.

I think we better replace stateless with shared-nothing since the latter is what the former really means.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s