AWS in 1 Min · Episode 177

Stateless applications on AWS explained

Keep state off the server. Watch the one-minute video, then read the details.

David Gomez1:08 video · 2 min read

"The server should remember each user." Not if it scales. When that server is replaced by Auto Scaling, or the next request lands on a different server, whatever it remembered is gone, and the user is logged out or loses their cart. Applications that scale well are stateless.

What stateless means

A stateless application keeps nothing on the server between requests. Every request carries, or can look up, everything needed to answer it. Because no server holds anything special, any server can answer any request.

The state still exists, of course. It just lives somewhere shared, outside the servers.

Where the state goes on AWS

  • Sessions (who is logged in, what is in the cart): Amazon DynamoDB or Amazon ElastiCache, both fast key-value lookups shared by every server. Signed tokens such as JWTs can also carry identity in the request itself.
  • Uploaded files: Amazon S3, not the instance's disk.
  • Data: a managed database such as RDS, Aurora or DynamoDB, outside the server.
  • Configuration and secrets: Parameter Store or Secrets Manager, read at start-up.

Why it pays off: cattle, not pets

Once servers hold nothing, they become cattle, not pets: interchangeable and disposable. An Auto Scaling group can add, remove or replace instances at any time and nobody notices. Deployments get easier too: start new instances with the new version, shift traffic, terminate the old ones. The same idea makes AWS Lambda and containers on Fargate work, since you never know which copy will run your next request.

Sticky sessions: a quick fix with a catch

An Application Load Balancer can use sticky sessions, which bind a user's session to one target, so an app that keeps sessions in memory appears to work behind several servers. It is a useful bridge while you move state out. But it is not resilience: if that instance fails or is scaled in, its users' state dies with it, and stickiness can also spread load unevenly.

A common mistake is treating sticky sessions as the solution and never moving the state. The fix is one shared session store.

Where AI fits

Models are stateless too. A model in Amazon Bedrock remembers nothing between calls. With the Converse API, AWS's documentation says you maintain context by including all the messages in the conversation in each new request. So your application carries the conversation: store the history (for example in DynamoDB, keyed by session ID) and send it, or a summary of it, with every call. Long histories cost input tokens on every turn, which is why trimming, summarizing and prompt caching matter.

For agents, Amazon Bedrock AgentCore Memory is a managed option: it keeps short-term memory of a session's turns and extracts long-term memory, such as user preferences, across sessions. Either way, the principle is the same as for web servers: state lives in a shared store, not in the thing that computes.

Quick recap

  • Keep state off the server: sessions in DynamoDB or ElastiCache, files in S3.
  • Any server, any request, so Auto Scaling can replace servers freely.
  • You carry the conversation: models are stateless, your app stores and sends history.
AWS in 1 Min #177 · 1:08

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS