Home > REST Constraints > Stateless


Short Definition

Services remain stateless between request/response message exchanges with service consumers.

Long Definition

The communication between a service and a consumer is regulated so that the consumer provides all data necessary for the service to understand each consumer request. Between requests, the service is not permitted to retain any state data specific to its interaction with the consumer instance, allowing it to exist in a stateless condition. Instead, session state is deferred to the consumer at the end of each request.

  • Consumer logic must be designed to preserve state data between requests and to issue request messages containing state data.
  • The request message must contain all of the state data necessary for the service to process the request, and the service must be able to "forget" the state data upon issuing the response without compromising the overall interaction.
  • Because the service is only involved in the automation of a solution when a consumer is actively making a request to it, in-between requests the service is "at rest," and therefore using less CPU, memory, or network resources on behalf of the consumer.
  • The service cannot be required to store data specific to a runtime instance of a service consumer. However, the service is still allowed to store data that is related to its own functional context.
  • Making consumers responsible for preserving state data alleviates the service from having to store and replicate potentially volatile data that is only relevant to the individual consumer program.
  • Deferring session state to consumers between requests frees up service memory resources, allowing the service to scale with the number of concurrent requests, rather than with the total number of concurrent consumers.
  • Messages can be understood by the service without the need to have inspected earlier messages. This can simplify service logic design and further reduce the complexity of debugging.
  • The requirement to repeatedly transmit potentially redundant state data can increase network traffic and processing overhead.
  • Reliability of state data can be both positively and negatively impacted: Service instance failures can be dealt with gracefully because the service does not retain state, but failure of the service consumer can result in a loss of state data.
Relationship to REST

While this constraint builds upon Client-Server, it helps enable Cache and Layered System.

Related REST Goals

Modifiability, Scalability, Performance (negative), Visibility, Reliability