How Amazon Designs Idempotent APIs (TLDR)
- Idempotency means that performing the same operation multiple times produces the same result, which is crucial for building reliable distributed systems where retries are common due to transient failures.
2. Amazon uses unique client request identifiers, often implemented as a ClientToken
in AWS APIs. When a request is made, the ClientToken
ensures that even if the operation is repeated due to retries, it will not result in duplicated actions. This approach allows for safe retries by returning a consistent response for the same operation, thus maintaining the "at most once" execution guarantee.
For instance, in the Amazon EC2 RunInstances
API, the AWS CLI or SDK generates a unique ClientToken
if not provided by the user. If a retry occurs, the same ClientToken
is used, and the API returns the same result as the initial request, ensuring no additional instances are launched inadvertently.
3. For handling edge cases like late-arriving requests where idempotency is maintained to ensure consistent behavior, they follow the “principle of least astonishment,” which ensures that even if a resource has been deleted, subsequent requests with the same identifier…