×

Search anything:

Stateless and Stateful architecture [explained]

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

In this article, we have explained the Idea of stateless and stateful architecture ind depth. There seems to be a raging debate as to which is better, stateless architecture or stateful architecture. Additionally, there various misconceptions about the correct definition of these terms, especially in client and server systems.

Table of content:

  1. Introduction: Stating a brief history
  2. Stateless Architecture
    3. Advantages of Stateless applications
    4. Disadvantages of Stateless applications
    5. Example of Stateless Application Architecture
  3. Stateful Architecture
    7. Advantages of Stateful applications
    8. Disadvantages of Stateful applications
    9. Example of Stateless applications

Introduction: Stating a brief history

Historically, since the internet and web applications were simple, stateless ruled. However, as sites needed to become more dynamic, handle user information and actions, stateful architecture and applications grabbed the trophy for some time before stateless became hip and cool again due to the need for scalable web applications. Stateful having ruled for a while may be the reason behind much of the hardline stance by some that stateful is always best ignoring various system design considerations.

Stateless Architecture

Stateless applications have no knowledge of the past and treat transactions, requests, processing, operations as independant of previous ones. Some of the features of stateless include:

  • Often do not store any client data generated in a session
  • Operations are carried out from scratch
  • Do not use state to process any requests
  • Same request produces the same response
  • Requests are self contained
  • Involve microservices and communications via message passing etc
  • Usually involve single service or function

Advantages of Stateless applications

Advantages of Stateless applications are:

  • Easy to implement
  • Self contained increasing visibility
  • Better able to handle crashes
  • Easier to scale horizontally
  • Allow for isolation reducing risk total failover
  • Easy intergration with HTTP a popular widely used stateless protocol

Disadvantages of Stateless applications

Disadvantages of Stateless applications are:

  • Can not store user information and have to rely on inefficient cookies
  • Are often limited to what can be done.

Example of Stateless Application Architecture

Example of Stateless Application Architecture include:

  • Content Delivery Networks(CDN)
  • print, Serverless functions
  • HTTP, containers, offline applications
  • Functional programming, Tokens, REST

Stateful Architecture

Stateful applications retain state and need to remember the past and apply it to current reponse, transaction, processing or operations. Some of the features of stateful include:

  • Store data, state in storage e.g databases like MySQL, MongoDB etc
  • Operations not carried from scratch
  • Use state, current transactions are affected by the past
  • Same request may produce different response depending on the state and context
  • Requests are not self contained
  • Involve many calls, processes, steps one after another.
  • Knowledge of the past allows them to be retained to previous state

Advantages of Stateful applications

Advantages of Stateful applications are:

  • Can do more complex things eg designing shopping carts

Disadvantages of Stateful applications

Disadvantages of Stateful applications are:

  • More complicated to implement
  • Harder to analyze as they are not self contained
  • Do not handle crashes well
  • Have higher risk of total failover
  • Are difficult to scale horizontally
  • User experience may be poor due to dependancies
  • Storage costs and complexities

Example of Stateless applications

Example of Stateless applications are:

  • FTP, Cookies, Sessions
  • AJAX
  • Storage, Databases, User Session
  • Stateful containers

With this article at OpenGenus, you must have a strong idea of stateless and stateful architecture in System Design. Enjoy.

Stateless and Stateful architecture [explained]
Share this