liveBook · Manning

Idempotent state machine

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

An idempotent state transition produces the same result whether it is performed once or repeatedly.

An idempotent state transition produces the same result no matter how many times it runs. This lets a fault-tolerant process retry an entire transition after a failure without creating an invalid state. section 16.3.1

The state machine tracks completed results rather than partial progress. In the Imagery application, the relevant states are Created, Uploaded, and Processed; intermediate upload or filtering progress is ignored. section 16.3.1

A practical transition follows this sequence:

  • Allow a retry when the process is already in the target state instead of rejecting it as an invalid transition. section 16.3.1
  • Repeat the DynamoDB update safely; duplicate updates do not harm the state machine. section 16.3.1
  • Permit repeated SQS messages only when the consumer is idempotent as well. section 16.3.1
  • Use a DynamoDB conditional update to combine the state check and update into one request, reducing races between concurrent processes. section 16.3.1

Imagery upload and processing

A process moves from Created to Uploaded with an S3 key, then from Uploaded to Processed with the S3 key of the sepia image. If sending the SQS message fails after DynamoDB succeeds, retrying repeats the safe state update and message publication. section 16.3 section 16.3.1

Figure 16.10 Combining AWS services to implement the asynchronous Imagery process

The architecture figure connects the asynchronous Imagery process with the AWS services used to implement it. section 16.3

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Explains transition rules, duplicate effects, idempotent consumers, and atomic conditional updates, but keeps the state model deliberately simple.
Examples
Demonstrates Created-to-Uploaded and Uploaded-to-Processed transitions for an asynchronous image-filtering workflow.
What you can do after
Apply it via DynamoDB conditional updates, retries, and idempotent SQS consumers.
How it connects
Connects state machines with DynamoDB, Amazon SQS, Amazon S3, EC2, asynchronous processing, and message consumers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.