Stateless Applications are an Illusion

Stateless applications have haunted me over the years. There is a mantra for web development: Keep your application stateless. I have seen companies pilling money on the effort to go stateless with their web applications. I’ve encountered a company with a multi million lines of code application with a stateful web framework going coniserable lengths to reengineer the app to being stateless. I have seen companies who don’t scale because they wanted to be stateless. All of this haunted me. Because it should not haunt you as a developer, I will take a deeper look and show that it’s impossible to keep most applications stateless.

To begin with, I divide state into two kinds:

  1. Application state (like Orders)
  2. Conversational state (temporary state during a session)

Some applications do not need state, or only have application state. The viewing part of CMS for example. One view sees applications as state machines and the essence of web requests to change this state. Beside the two kinds of state, there are at least two dimensions of state:

  1. accidental, framework state
  2. use case driven state, often the conversational state from above

The first dimension of state, framework state, can be designed away. There are frameworks which keep state during their operation – Tapestry for example. By chosing the right framework and architecture, you can minimize or prevent framework state. The second dimension cannot be designed away. If your use case calls for state, you need to store that state. A checkout process comes to mind: customers choose over serveral pages delivery address and payment information. Baskets come to mind: they store their conntent often only during a session. That conversation state needs to be hold somewhere.

When people talk about stateless applications, they in fact mean no state in the web tier. But state can be stored in several layers:

  1. Best state store: Client ( hack, Javascript variables for AJAX applications, Cookies)
  2. Pages (e.g. with JS variables or Hidden fields)
  3. Easiest state store: Web Tier (HTTPSession in Java applications)
  4. Infrastructure (Cache like Memcached, Databases like MySQL, NoSQL like Redis)

You need to decide where to put your conversation state, but you cannot prevent your app from having state if the use case calls for it. What about using the easiest and fastest state store, your web tier? ThePlay framework says:

But this is much better because a session is not the place to cache your application data!

Contrary to this, your web tier session is a very good place to cache your application data. Problems do not arise when your web session is a cache (might arise if you do not handle stale data, but every cache has that problem), and can be constructed easily with the help from a persistent state store. e.g. store the UserId in a persistent store like Redis, cache the User object in your session. In case of a session failover, the new server will reconstruct the session from your persistent state store. Many developers do not like web tier state because your web tier does not allow easy failover and scaling. But when thinking the session as a cache, not a state store, no problems arise in case of taking down one web tier server.

As always there are trade offs, there is no best solution, be it web tier caching or “stateless” applications. As a developer you need to decide between the different trade offs of state storage.

192 thoughts on “Stateless Applications are an Illusion”

  1. Pingback: best
  2. Pingback: fucoxanthin
  3. Pingback: geniux pills
  4. Pingback: intelligex
  5. Pingback: intellux
  6. Pingback: radian c
  7. Pingback: supreme antler
  8. Pingback: genius reviews
  9. Pingback: TRACKR BRAVO
  10. Pingback: alpha man pro
  11. Pingback: alpha peak
  12. Pingback: alpha xtrm
  13. Pingback: caralluma extract
  14. Pingback: anabolic rx24
  15. Pingback: cognifocus
  16. Pingback: max synapse
  17. Pingback: nerventrax
  18. Pingback: nutra forskolin
  19. Pingback: premium cleanse
  20. Pingback: testorip
  21. Pingback: testoroar
  22. Pingback: zynev
  23. Pingback: pro forskolin
  24. Pingback: forskolin slim
  25. Pingback: garcinia cleanse
  26. Pingback: forskolin fuel
  27. Pingback: vitapulse
  28. Pingback: Vita pulse
  29. Pingback: vitapulse reviews
  30. Pingback: vitapulse review
  31. Pingback: somnapure
  32. Pingback: perfect biotics
  33. Pingback: reviews vitapulse
  34. Pingback: vitapulse scam
  35. Pingback: vitapulse
  36. Pingback: vitapulse
  37. Pingback: vita pulse
  38. Pingback: probiotic america
  39. Pingback: taurus traits
  40. Pingback: How To Cure ED pdf
  41. Pingback: Everyday Roots
  42. Pingback: Fat Loss Factor
  43. Pingback: Diabetes 60 System
  44. Pingback: Ecomaxx
  45. Pingback: T90 Xplode Reviews
  46. Pingback: Maxtropin
  47. Pingback: Tea Tox Review
  48. Pingback: Forever Bust
  49. Pingback: MegaDrox Review
  50. Pingback: Test X180
  51. Pingback: Test X180
  52. Pingback: Breast Actives
  53. Pingback: vitapulse
  54. Pingback: recapture 360
  55. Pingback: probiotics america
  56. Pingback: Perfect Biotics
  57. Pingback: Homepage
  58. Pingback: have a peek here
  59. Pingback: check my blog
  60. Pingback: a fantastic read
  61. Pingback: see it here
  62. Pingback: great post to read
  63. Pingback: my review here
  64. Pingback: Get More Info
  65. Pingback: this page
  66. Pingback: Check This Out
  67. Pingback: see here
  68. Pingback: original site
  69. Pingback: Woman Men Adore
  70. Pingback: read review
  71. Pingback: see this here
  72. Pingback: check my site
  73. Pingback: their explanation
  74. Pingback: my site
  75. Pingback: more info here
  76. Pingback: their explanation
  77. Pingback: visit
  78. Pingback: find more
  79. Pingback: visit
  80. Pingback: read more
  81. Pingback: check it out
  82. Pingback: internet
  83. Pingback: click
  84. Pingback: other
  85. Pingback: my response
  86. Pingback: official site
  87. Pingback: check my site
  88. Pingback: their explanation
  89. Pingback: see this here
  90. Pingback: find more
  91. Pingback: more info
  92. Pingback: 60 day fix review
  93. Pingback: click here
  94. Pingback: tires
  95. Pingback: rims
  96. Pingback: read more
  97. Pingback: click here
  98. Pingback: read more
  99. Pingback: read more
  100. Pingback: click here

Comments are closed.