Cloud concept · Updated

Idempotency - Idempotency is the property that repeating an operation with the same intent has the same intended effect as performing it once.

In short

Idempotency makes retries safe when requests time out, events arrive more than once, or automation restarts after a failure. In incident response, it prevents repeated remediation attempts from creating duplicate resources, reversing containment, or causing additional disruption.

Cloud Concepts Hub →

6 key aspects of Idempotency

Idempotent automation combines stable intent, durable request identity, concurrency controls, and recovery testing to make repeated remediation safe.

01
Stable effects under repetition

Repeated execution of the same logical action should preserve its intended result. Prefer setting an explicit target state over toggling, incrementing, or appending without safeguards.

02
Consistent request identity

Reuse a stable key across retries and bind it to the action's parameters and scope. Separate genuinely new remediation actions from duplicate deliveries of an existing action.

03
Concurrency-safe coordination

Use conditional writes or equivalent atomic controls to prevent simultaneous workers from claiming the same action. A separate read followed by an unconditional write is not sufficient.

04
Partial-failure recovery

Handle crashes between an external side effect and the recording of its completion. Prefer API-supported idempotency tokens, and otherwise reconcile the destination before repeating uncertain work.

05
Explicit retention and lifecycle

Keep deduplication records long enough to cover the expected retry and replay window. Define how expired claims, failed actions, and later incidents are handled without silently suppressing required remediation.

06
Testable remediation outcomes

Inject duplicate events, concurrency, and timeout failures into incident-response exercises. Verify that containment remains effective, evidence is preserved, and repeated execution does not introduce additional changes.

Cloud services for Idempotency

Lambda or Systems Manager Automation can execute remediation actions, while Step Functions coordinates sequencing, retries, and failure handling. DynamoDB can hold stable action identifiers and execution status so concurrent or repeated invocations recognize work already claimed or completed. Downstream EC2 operations should use supported client tokens where available and reconcile uncertain results where they are not. ARC recovery actions should request explicit routing-control states rather than reverse whatever state currently exists. Across these services, the workflow must distinguish a duplicate attempt from a new authorized action and verify the resulting containment or recovery state.

AWS LambdaAWS Lambda

Lambda functions can receive duplicate events and must make remediation side effects retry-safe. The Powertools for AWS Lambda idempotency utility can coordinate duplicate invocations through a persistence store, but external side effects still require careful failure handling.

AWS Step FunctionsAWS Step Functions

Step Functions coordinates remediation workflows with retries and error handling. Each task that changes external state must tolerate repetition, because workflow orchestration does not make its downstream side effects inherently idempotent.

AWS Systems ManagerAWS Systems Manager

Systems Manager Automation executes incident-response runbooks that can inspect current state, apply targeted changes, and verify results. Supported automation requests can use client tokens, but runbook steps must also remain safe when executions are retried or started again.

Amazon DynamoDBAmazon DynamoDB

DynamoDB conditional writes can atomically claim idempotency keys and store action status, parameters, and results. TTL can clean up old records, but expiration logic must not assume that expired items are deleted immediately.

Amazon EC2Amazon EC2

Some EC2 APIs support client tokens for idempotent requests, subject to operation-specific rules. Incident-response automation must check the particular API rather than assume that every containment or forensic resource-creation operation has the same retry behavior.

Idempotency exam questions

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

MLA-C02 (beta)

A company runs a Spark Structured Streaming application on Amazon EMR to prepare equipment telemetry for ML training. Each source record has a globally unique reading_id and an immutable payload. The application deterministically calculates normalized numeric features and uses foreachBatch to insert them into an external relational database. Each inserted row currently receives a database-generated identifier.

The application uses a durable checkpoint. During a failure, a database write can commit before Spark records the micro-batch as completed. After recovery, replaying that micro-batch creates additional feature rows. The database supports unique constraints and atomic upserts.

The company must retain one feature row for every reading and transformation version, including after failures and replays. Which change should the ML engineer make?

Show answerCORRECT ANSWER

Configure a unique key on reading_id and transformation version. In foreachBatch, atomically upsert the deterministic feature values using that key instead of inserting rows with new identifiers.

The same logical reading and transformation version always target the same database row. Repeating a committed write replaces the row with the same feature values rather than adding another row. Failed or partially completed batches can therefore be retried without losing readings or creating duplicates.

SAP-C03

A company runs licensed simulation workers as an Amazon ECS service. When a worker becomes unhealthy, ECS replaces its task. An existing coordinator confirms that the failed worker can no longer run and asynchronously invokes an AWS Lambda function to return the worker's reserved license seats to an available-seat counter in Amazon DynamoDB.

Each simulation attempt has a globally unique attempt ID and a DynamoDB reservation item containing the reserved seat count and a status of RESERVED or RELEASED. The available-seat counter is stored in a separate item. Replacement attempts receive new attempt IDs and separate reservations. Reservation items are retained longer than the maximum event replay period.

The same failed-attempt event can invoke the function concurrently more than once. The function can also time out after a DynamoDB request succeeds but before it receives the response. Every confirmed failed attempt must eventually return its seats, but no attempt may increase the available-seat counter more than once. Recovery must remain automatic after transient failures.

Which implementation meets these requirements?

Show answerCORRECT ANSWER

Use TransactWriteItems to conditionally change the reservation from RESERVED to RELEASED and increment the available-seat counter by the reserved count in the same transaction. Retry transient failures. If the condition fails, verify that the reservation is already RELEASED and treat that result as successful completion.

The transaction commits both changes or neither change. The condition on the stable attempt-specific reservation allows only one transaction to return the seats. Concurrent invocations and retries after an ambiguous response cannot increment the counter again. Transient failures can be retried without leaving a partially completed release, and separate replacement attempts retain independent reservations.

SOA-C03

A CloudOps engineer investigates an abnormal network traffic alarm on an EC2 instance. The response procedure requires a custom AWS Systems Manager Automation runbook to replace all security groups on the instance's primary network interface with an approved quarantine security group. The runbook must preserve the original security-group set for a separate, authorized restoration procedure.

Repeated alarm notifications can start additional executions for the same incident and network interface. These executions run sequentially, but an execution can fail after any step. A later execution must complete containment without replacing the saved original configuration with the quarantine configuration. A durable data store is available to the runbook.

Which runbook design meets these requirements?

Show answerCORRECT ANSWER

Use the incident ID and network interface ID as the storage key. Before changing the interface, atomically create the original-configuration record only if it does not exist. Retain any existing record, ensure that the interface has exactly the quarantine security group, and verify the resulting configuration.

The stable key associates repeated executions with the same logical remediation. Creating the baseline only if absent preserves the original configuration, and persisting it before modification prevents its loss. Every execution can then enforce and verify the same quarantine state, including when a previous execution failed after saving the baseline.

Practice Idempotency in a full exam

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

Start a free practice exam

What is Idempotency

3 min read

Idempotency describes an operation whose intended effect does not change when the same logical request is repeated. Setting a resource to a specified state is often idempotent; toggling its state usually is not. For example, setting a routing control to OFF expresses a stable target, whereas switching it to the opposite of its current state could reverse the first action when retried. Idempotency concerns the intended effect, not necessarily identical response codes, timestamps, logs, or execution counts.

Cloud automation needs this property because a caller cannot always tell whether an operation succeeded. A request may complete at the destination while its response is lost. Event delivery, queue processing, and workflow retries can also invoke the same remediation more than once. Treating every invocation as a new incident action can produce duplicate forensic snapshots, repeated notifications, conflicting containment changes, or unnecessary failovers.

Design incident-response runbooks around explicit desired states. An isolation step might ensure that a network interface has the approved quarantine security-group set rather than repeatedly adding or removing individual groups without checking the intended configuration. Preserve the original configuration once for authorized restoration, and avoid overwriting that baseline on subsequent executions. Verify containment afterward, because idempotency does not prove that a remediation is correct or sufficient.

When an action creates a new resource or produces another nonrepeatable side effect, assign a stable idempotency key to the logical action. A useful key can combine the incident identifier, target resource, remediation type, and remediation version. Retries must reuse the key; a random identifier generated for each attempt defeats deduplication. Where an API supports a client token, follow its documented scope, retention period, and parameter-matching rules. Otherwise, maintain durable execution records with conditional writes and track in-progress, completed, and failed work.

Concurrency requires more than checking whether a record exists. Two workers can both observe an absent record and perform the same action unless ownership is claimed atomically. There is also a failure window between completing an external action and recording its success. A database lock alone cannot make those separate operations atomic. Use destination-side idempotency when available, or reconcile existing resources using recorded identifiers and stable correlation metadata before retrying. Expired ownership records need a recovery strategy, not unconditional reexecution.

AWS Lambda functions and Systems Manager Automation runbooks must implement these safeguards in their actions; using a managed execution service does not make arbitrary code idempotent. Step Functions retries likewise require retry-safe tasks. Forensic workflows, including those built with Automated Forensics Orchestrator for Amazon EC2, should distinguish retrying an existing evidence-acquisition action from intentionally collecting new evidence. Application Recovery Controller automation should request explicit routing-control states and respect safety rules rather than blindly toggle traffic.

Idempotency adds storage, coordination, latency, and operational complexity. Deduplication records retained too briefly permit old events to repeat actions; records retained without appropriate scope can suppress legitimate later incidents. It is not a guarantee of exactly-once execution, a substitute for authorization, or a rollback mechanism. Test runbooks with duplicate events, concurrent invocations, lost responses, partial completion, and retries after recovery, then confirm both the final resource state and the absence of unintended duplicate effects.

Learn Idempotency in lessons

13 short lessons on Idempotency in 8 certification courses.

and 7 more lessons

Open the lessons