Stateless Architectures Win

Johann Gyger
Oct 31, 2017 · 2 min read
Image for post
Image for post

Computing in distributed systems is difficult. However, we live in a distributed world: the Internet, web apps, and most mobile apps would not be able to run on only one huge central server. So if your solution isn’t a niche for a handful of users you’re better off with a stateless architecture.

Benefits

There are three major benefits:

HTTP and REST

The probably most successful and widespread application of a stateless architecture is the Hypertext Transfer Protocol (HTTP). The Internet wouldn’t be possible without HTTP. Representational State Transfer (REST) is an architectural style that formalizes some of the HTTP design decisions. Both HTTP and REST are tremendously successful.

Stateless Services

Remember EJB 2.1 Stateful Session Beans? I do. They were beasts. Accidental complexity at its best. So let’s forget about them and let’s concentrate on stateless services. That’s how I learned to build web applications 15 years ago and it proved to be the right approach in almost any case. The programming model is simple and easy to understand.

State — on the other hand — needs to be handled differently. It belongs to a backing service such as a database that is specialized to cope with it.

Serverless

Serverless applications are not bound to a specific server or group of servers. Instead, every request is executed on an ephemeral server which is shared with other serverless applications. So there is no chance of maintaining server-side session state. State has always to be persisted using third-party or backing services.


There’s always a trade-off when architecting an application. Adding state like session data doesn’t make it easier. Scalability is limited, fault tolerance is limited and you’ll potentially end up using some proprietary clustering mechanism. So my belief is that stateless architectures are the better approach in almost any case.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store