Cloud Architecture : Building stateless and stateful architecture design

Kamran Ghyan
2 min readJan 24, 2021

While designing a complex application such as Netflix, need to handle the user state to maintain activity flow, where users performing a chain of activities such as, watching movie, plan setting, setting payment method and make payment. User can use various channel to access website, while checkout and making payment user switch from mobile to laptop. In this situation application should persist user activities and maintain their state until the transaction is complete.

To persist user states and make applications stateless, user-session
information needs to be stored in persistent database layers such as the
NoSQL database.

Persist state can share b/w multiple web servers or micro-services. In monolithic application uses stateful architecture user-session is stored in server it self rather then persistence database.

One of the major draw back of stateful application is it doesn’t support horizontal scaling very well. Because the application state persist with in the server which cannot be replaced.

Let say you have millions of users active, for efficient horizontal scaling it is important to handle large user base and achieve low application latency. To achieve that goal stateless architecture is ideal.

In a stateful application, state information is handled by the server, so once
users establish a connection with a particular server, they have to stick with
it until the transaction completes. But that situation is not in case of stateless architecture.

Our design approach should focus more on the shared session using stateless architecture approach, as it allows horizontal scaling very well.

In following diagram shows a stateless architecture.

A stateless application architecture

The above architecture diagram is a three-tier architecture with a web,
application, and database layer. To make applications loosely coupled and
scalable, all user sessions are stored persistently in the NoSQL database, e.g Amazon DynamoDB. You should use client-side storage, such as
cookies, for the session ID. This architecture allow to scale-out
pattern without having to worry about a loss of user state information. A
stateless architecture removes the overhead to create and maintain user
sessions and allows consistency across the application’s modules. A stateless
application has performance benefits too, as it reduces memory usage from
the server-side end and eliminates the session timeout issue

--

--

Kamran Ghyan

Software Engineer, System Architecture, Cloud Architecture, AI enthusiastic