Deciding between stateful and stateless approaches
Stateful and stateless are two opposite ways to implement APIs, each with their own pros and cons.As the name suggests, stateful software's behavior depends on its internal state. Let's take a web service, for instance, as shown in Figure 2.1. If it remembers its state, the consumer of the service can send less data in each request, because the service remembers the context of those requests. However, saving on the request size and bandwidth has a hidden cost on the web service's side. If the user sends many requests at the same time, the service now has to synchronize its work. As multiple simultaneous requests can change the state, not having synchronization could lead to data races, which cause undefined or unpredictable behavior.
If the service was stateless, however, then each request coming to it would need to contain all the data needed to process it successfully. This means...