Cloud concept · Updated

Statelessness - Statelessness is a design principle in which a processing instance does not depend on locally retained client or workflow state from previous requests.

In short

A stateless component processes each request using information supplied with that request and, when necessary, state retrieved from external systems. This makes processing instances interchangeable, simplifying horizontal scaling, failure recovery, and deployment without requiring the overall application to stop storing data.

Cloud Concepts Hub →

6 key aspects of Statelessness

Statelessness makes compute replaceable by keeping request context explicit and durable state independent of individual instances.

01
Request-independent processing

Each request supplies enough context to identify the caller, operation, and relevant resources. Processing must not depend on a previous request having reached the same instance.

02
Externalized durable state

Store business records, session data, and workflow progress outside individual compute instances. Select storage according to durability, consistency, access patterns, and recovery requirements.

03
Interchangeable compute instances

Any healthy instance running the appropriate application version can handle a request. This reduces the need for sticky sessions and makes scaling, replacement, and rolling deployments easier.

04
Disposable local optimizations

Local caches, reused connections, and temporary files can improve efficiency but must not be the only copy of required state. Losing an instance should affect performance or in-flight work, not erase committed business data.

05
Explicit retry and concurrency controls

Stateless processing does not prevent duplicate side effects or conflicting updates. Combine idempotency keys, durable operation records, and conditional updates or transactions where required.

06
Protocol-aware implementation

Check whether the selected protocol, transport, and SDK require server-side sessions or persistent connections. For MCP tools, choose stateless operation where supported rather than assuming that a client library or deployment platform removes session requirements.

Cloud services for Statelessness

API Gateway can receive requests and pass them to Lambda functions, while ECS runs containerized services or more complex tool servers. Both compute approaches can remain replaceable by storing records in DynamoDB and files in S3 rather than relying on local memory or disk. Step Functions can retain orchestration state across multiple processing steps, retries, and waits. The resulting application is not state-free: it separates scalable processing from durable state management. Engineers must still design storage capacity, authorization, concurrency controls, and idempotency so that adding workers or retrying requests does not compromise correctness.

AWS LambdaAWS Lambda

Lambda supports request-driven and event-driven processing with independently managed execution environments. Keep durable state external, treat environment reuse as an optimization, and use compatible transports when implementing stateless MCP tools.

Amazon DynamoDBAmazon DynamoDB

DynamoDB can hold session records, workflow checkpoints, and idempotency records shared by stateless workers. Conditional writes and transactions help coordinate concurrent operations; the database remains the stateful part of the architecture.

Amazon API GatewayAmazon API Gateway

API Gateway provides an API entry point for backends such as Lambda functions. Explicit authentication and resource context let backends process requests without relying on instance-local sessions, but the gateway does not enforce stateless application behavior.

Amazon S3Amazon S3

S3 stores durable files and artifacts outside compute instances. Passing object references between processing steps avoids relying on local files surviving function invocations or container replacement.

AWS Step FunctionsAWS Step Functions

Step Functions maintains workflow execution state while coordinating individual processing steps. This allows workers to remain stateless even when the overall business process is long-running and stateful.

Statelessness exam questions

Real practice exam questions on Statelessness, with the correct answer and its explanation. Answer them with every option in the exam simulator.

DEA-C01

A company uses an AWS Glue Spark job to ingest each supplier delivery into an Amazon S3 data lake. The job validates and normalizes each record independently, without retaining information from previously processed records. A delivery contains files for several business dates.

Analysts query the destination while ingestion is running. Each query must see either none or all of a delivery's new records, never a partially published delivery. If the job fails before publishing the delivery, previously committed data must remain queryable and unchanged. The query engine supports Apache Iceberg tables.

Which design meets these requirements?

Show answerCORRECT ANSWER

Use an Apache Iceberg destination table and append the entire delivery through one table commit. Keep the record-level transformations independent of prior records.

An Iceberg table commit atomically publishes a new snapshot containing the delivery's changes. Snapshot-aware queries see the previously committed table or the newly committed table, not a partially published delivery. Files written before a failed commit are not part of the committed table snapshot. Stateless record transformations and transactional destination writes are compatible: they describe different aspects of the pipeline.

SAP-C03

A company runs a stateless document-sharing API on an automatically scaled container fleet. The API stores temporary access grants in an Amazon DynamoDB table. Each request includes a grant ID, and any container must be able to authorize the request without relying on local state.

A grant must stop authorizing document access at its expiration time, even if its record still exists. A separately authorized administrative operation can reactivate an expired grant that has not yet been deleted by assigning a new expiration time. The reactivated grant must remain eligible for automatic cleanup after its new expiration. Physical deletion can occur several days after expiration. The company does not want scheduled cleanup jobs or application-issued cleanup deletes.

Which implementation meets these requirements?

Show answerCORRECT ANSWER

Enable TTL on an expiresAt attribute stored as a Number containing Unix epoch seconds. On every authorization request, reject missing grants and grants whose expiresAt is not in the future. For an approved reactivation, update the existing item's expiresAt to the new future timestamp. Allow TTL to clean up expired items asynchronously.

DynamoDB TTL requires a Number containing Unix epoch time in seconds. Expired records can remain for a few days, so the API must enforce expiration independently of physical deletion. Updating an expired item's TTL to a future timestamp before deletion makes it no longer expired and preserves automatic cleanup at the new expiration. TTL deletion does not consume write throughput in the source Region.

DVA-C02

An AWS Lambda function serves a multi-tenant API. Each request contains a signed token identifying the caller and tenant. To improve performance, a developer initializes an AWS SDK client outside the handler and stores the first request's decoded caller identity in a module-level variable. Later requests sometimes execute with the wrong tenant's identity. The function must authorize each request independently while retaining safe initialization optimizations. Which code change best meets these requirements?

Show answerCORRECT ANSWER

Keep the SDK client outside the handler, but validate each request's token and hold its caller identity in handler-local variables that are passed explicitly to authorization logic.

An SDK client configured independently of the caller can safely be reused for efficiency. Caller identity is request-specific state and must be derived from the current request. Keeping that context local prevents correctness from depending on an execution environment's invocation history.

Practice Statelessness in a full exam

Questions on Statelessness in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is Statelessness

3 min read

Statelessness describes the relationship between requests and the components that process them. A stateless application instance does not need to remember an earlier interaction to handle the next one correctly. Each request supplies the necessary context, such as an authentication token, resource identifier, or workflow identifier, and the instance retrieves any required persistent data from an external store. The application can still maintain orders, user profiles, conversation history, and other business state; that state simply does not depend on one particular processing instance remaining alive.

This separation makes horizontal scaling practical. A load balancer can distribute requests across interchangeable instances without requiring session affinity, also called sticky sessions. If an instance fails or is replaced during a deployment, another instance can continue serving requests using the same external records. By contrast, a shopping cart stored only in one application's memory ties the customer to that instance and risks data loss when it terminates. Storing the cart in a shared database removes that dependency, although the database itself remains stateful and needs appropriate availability and recovery controls.

Serverless functions are a common application of this principle. An order-processing function can receive an order identifier, read the order from a database, perform validation, and persist its result. It must not assume that a later invocation will use the same execution environment. Reusing database connections or caching reference data in memory can improve performance, but correctness must not depend on those optimizations surviving. Temporary files are likewise unsuitable as the sole durable record of completed work. Serverless infrastructure does not automatically make application code stateless.

Statelessness also supports microservice independence. Services exchange explicit identifiers and well-defined messages rather than relying on shared process memory. Long-running business processes can keep their progress in a workflow engine or database while short-lived workers perform individual steps. Stateless workers still need concurrency controls: two workers updating the same record can conflict, so conditional writes, transactions, or version checks may be necessary.

For agentic AI, a lightweight Model Context Protocol, or MCP, tool server can use stateless request handling to expose operations such as looking up inventory. A Lambda-based implementation should use a transport and SDK configuration that support stateless operation and fit the function's execution constraints. Authentication and tool arguments accompany requests, while durable conversation or task state stays outside the execution environment. MCP client libraries provide consistent protocol handling, but they do not automatically eliminate server-side session requirements. Container-based servers, such as those running on Amazon ECS, can accommodate complex dependencies or longer-lived connections; containers are not inherently stateful, and externally managed state still improves their replaceability.

The main trade-off is that moving state out of compute introduces network calls, storage costs, latency, and dependencies on external systems. Shared stores must scale with the compute tier, and consistency requirements must be explicit. Carrying excessive state in client tokens can increase request size and expose sensitive information unless properly protected. Statelessness also does not imply idempotency: retrying a stateless payment operation can still charge a customer twice. Use idempotency keys and durable duplicate detection where retries could repeat side effects. In architecture questions, distinguish replaceable compute from durable state, and do not mistake sticky sessions, automatic scaling, or managed hosting for proof that an application is stateless.

Learn Statelessness in lessons

6 short lessons on Statelessness in 5 certification courses.

Open the lessons