liveBook · Manning

Stateless system

As explained in Grokking Software Architecture

An architectural approach in which application servers avoid retaining state locally between requests, typically storing necessary state elsewhere.

Imagine a bartender with amnesia: “Another one, please” is not enough. You must identify yourself and say what you want each time. A stateless server works similarly: it does not retain the client’s conversation between requests, so each request supplies the context needed to process it. section 6.2.3

Adding fries to an order

Instead of asking for “fries with that,” a client identifies the order and asks to add fries to order #55. Any suitable server can handle the request without remembering the earlier conversation. section 6.2.3

Stateless does not mean the application has no data. It means application servers do not keep necessary session data or files locally between requests. Store that state in an external database or cloud storage instead, so servers can be replaced and requests can be handled by different instances. section 9.12 section 9.3.3

Listing 9.1 Stateful Design vs. Stateless Design
# Wrong (Stateful): Saves user upload to the fragile local filesystem
with open('profile.jpg', 'wb') as f:
    f.write(user_upload)
 
# Right (Stateless): Saves user upload directly to an external S3 Bucket
import boto3
boto3.client('s3').put_object(Bucket='mybucket', Key='profile.jpg', 
Body=user_upload)

Compare a user upload saved on the server’s local filesystem with one sent directly to an external S3 bucket. section 9.3.3

The payoff is flexibility: a load balancer can send requests to identical application servers, and losing one need not mean losing data already stored externally. The tradeoff is that requests need enough context and important data must live outside the application instance. Stateless application servers do not make the data layer disposable; databases still need careful persistent change management. section 6.2.3 section 9.3.3 section 9.8.3

Statelessness is also a REST constraint: each request acts on its own. In serverless environments, the rule matters because an execution environment can disappear; do not rely on a local file or global variable to preserve important data for the next run. section 6.9.1 section 9.5.2

How Grokking Software Architecture covers it

How deep it goes
Explains request context and external state with analogies and a short storage comparison.
Examples
Illustrates stateless requests with a burger order and contrasts local file uploads with S3 storage.
What you can do after
Evaluate application designs for request context and locally retained session data or files.
How it connects
Connects statelessness to REST, load balancing, dependency inversion, and immutable infrastructure.

Also explained in

Compare how 16 books explain stateless system →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.