# Idempotency

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

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/idempotency

> 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.

Practice exams covering Idempotency: [ANS-C01 AWS Certified Advanced Networking - Specialty](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty), [SOA-C03 AWS Certified CloudOps Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate), [DEA-C01 AWS Certified Data Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate), [DVA-C02 AWS Certified Developer - Associate](https://blowstack.com/practice-exams/aws-certified-developer-associate), [DOP-C02 AWS Certified DevOps Engineer - Professional](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional), [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [MLA-C02 (beta) AWS Certified Machine Learning Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate), [SCS-C03 AWS Certified Security - Specialty](https://blowstack.com/practice-exams/aws-certified-security-specialty), [SAA-C03 AWS Certified Solutions Architect - Associate](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate), [SAP-C03 AWS Certified Solutions Architect - Professional](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional).

## 6 key aspects of Idempotency

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

1. **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.
2. **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.
3. **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.
4. **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.
5. **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.
6. **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 Lambda](https://blowstack.com/tools/cloud-services-hub/aws-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 Functions](https://blowstack.com/tools/cloud-services-hub/aws-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 Manager](https://blowstack.com/tools/cloud-services-hub/aws-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 DynamoDB](https://blowstack.com/tools/cloud-services-hub/amazon-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 EC2](https://blowstack.com/tools/cloud-services-hub/amazon-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.

### Question 1 (MLA-C02 (beta))

**Question:**

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?

**Correct 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.

**Explanation:** 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.

### Question 2 (SAP-C03)

**Question:**

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?

**Correct 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.

**Explanation:** 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.

### Question 3 (SOA-C03)

**Question:**

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?

**Correct 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.

**Explanation:** 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.

### Question 4 (AIP-C01)

**Question:**

A training company exposes an enroll_in_session tool through an AWS Lambda function to its generative AI assistant. The tool stores enrollments and a session's remaining-seat counter in Amazon DynamoDB. Each employee can enroll only once in a given session. An enrollment must consume exactly one seat and return a durable confirmation ID.

The agent runtime can retry a tool invocation after a timeout, and invocations for the same employee and session can overlap. Lambda might time out after DynamoDB commits a write but before returning the result. Only this tool creates enrollments or changes seat counters; cancellations are not supported. Enrollment records remain available throughout the retry period.

The company requires every confirmed enrollment to correspond to exactly one consumed seat. A retry of a successful enrollment must return its original confirmation, even if the session is now full. A failed attempt must not leave an enrollment without consuming a seat or consume a seat without creating an enrollment.

Which implementation meets these requirements?

**Correct answer:** Read any existing enrollment consistently and return its stored confirmation if present. Otherwise, use TransactWriteItems to conditionally create an enrollment keyed by employee ID and session ID and decrement the session counter only if it is positive. If the transaction fails or its outcome is uncertain, consistently check for the enrollment before deciding whether to retry or report that the session is full.

**Explanation:** The transaction commits the unique enrollment and seat decrement together or neither. The conditional enrollment write prevents overlapping calls from consuming multiple seats. A consistent lookup recovers the original confirmation after an uncertain response and lets an existing enrollment succeed even when no seats remain.

### Question 5 (DEA-C01)

**Question:**

A utility company uses an AWS Lambda event source mapping to process meter events from Amazon Kinesis Data Streams. Each event contains a unique event ID, and producers publish each event only once. The function updates a billing database. In a single database transaction, it checks for the event ID in a processed-events table, applies the billing update only if the ID is absent, and inserts the ID. Entries in the processed-events table are automatically deleted 24 hours after insertion.

The stream retains records for 7 days. Engineers sometimes replay retained records through the function after correcting unrelated processing issues. A replay can finish up to 7 days after an event was first processed. Immediate retries do not duplicate billing updates, but replays performed several days later sometimes do.

The company must prevent duplicate billing updates while preserving automatic retries and the full replay capability. Which change should a data engineer make?

**Correct answer:** Retain processed-event entries for at least 8 days after insertion, and continue checking and updating the database within the existing transaction.

**Explanation:** The durable record of a completed update must outlive every supported retry and replay. Eight days exceeds the maximum 7-day interval between initial processing and replay completion. Keeping the check, billing update, and event-ID insertion transactional also protects against concurrent processing and failures.

### Question 6 (SCS-C03)

**Question:**

A security team is designing an automated incident response workflow. For each finding, existing AWS Lambda functions quarantine an affected resource, create an evidence package, and update an incident ticket. Some actions can succeed even when the caller times out before receiving the response. The same finding can also be delivered more than once.

The response plan requires automatic retries of transient failures, execution of each dependent action only after the preceding action succeeds, and notification to responders when retries are exhausted. Repeated processing must not create duplicate evidence packages or incident tickets. The team wants managed workflow orchestration rather than custom orchestration code.

Which solution best meets these requirements?

**Correct answer:** Use a Standard AWS Step Functions workflow with synchronous Lambda invocations, bounded Retry policies for transient errors, and Catch transitions to a responder-notification path. Pass stable incident-and-action idempotency keys to the functions, which use durable deduplication records and reconcile uncertain outcomes before repeating side effects.

**Explanation:** Synchronous invocation lets the workflow sequence actions based on their results and handle function failures. Retry and Catch provide managed retry and escalation paths. Stable keys reused across task retries and duplicate workflow executions, combined with durable deduplication and reconciliation, prevent repeated side effects when an earlier action might already have succeeded.

### Question 7 (DVA-C02)

**Question:**

A security application uses Amazon EventBridge to invoke an AWS Lambda function that quarantines an EC2 instance by replacing its security groups with a designated quarantine security group. The function must save the instance's original security groups for later authorized restoration.

In a development environment, an integration test publishes two events with the same incidentId and instanceId but different EventBridge event IDs. The test also forces the function to fail immediately after changing the instance's security groups, then retries processing in a new execution environment. After processing, the instance must remain quarantined, and the saved restoration data must still contain its pre-incident security groups.

Which implementation will meet these requirements?

**Correct answer:** Conditionally create a durable restoration record keyed by incidentId and instanceId only if it does not exist, and require that record to exist before changing security groups. On every attempt, ensure that the instance's security groups are set to the quarantine group without replacing an existing restoration record.

**Explanation:** The stable incident and instance identifiers associate all attempts with the same logical action. Saving the original configuration before making changes, without overwriting it on retries, preserves restoration data. Reapplying the same quarantine configuration leaves the instance quarantined even after a failure or execution-environment replacement.

### Question 8 (DOP-C02)

**Question:**

A company uses Amazon Application Recovery Controller (ARC) routing controls for application failover. During an approved incident, an AWS Lambda function must turn a specified routing control OFF and confirm its state before reporting successful remediation. Other routing controls must remain unchanged. The applicable safety rules permit this change, and no other workflow or operator will modify the control during remediation.

The incident workflow can deliver duplicate requests with different delivery IDs and can retry failed Lambda invocations. Testing shows that an ARC update can succeed even when the API response times out. The current function runs a helper that reads the routing control state and switches it to the opposite state.

Which implementation will meet the requirements despite duplicate requests and ambiguous API outcomes?

**Correct answer:** Replace the helper with a call to UpdateRoutingControlState that specifies OFF for the identified control. After a timeout, retry with the same target state. Use GetRoutingControlState to confirm OFF before reporting success, and fail the invocation if confirmation cannot be obtained within the execution deadline.

**Explanation:** Setting an explicit target state makes repeated requests converge on OFF rather than reversing an earlier successful change. Retrying after an ambiguous timeout is safe because every attempt requests the same state. Reading the state before reporting success also prevents an unconfirmed API outcome from being treated as completed remediation.

### Question 9 (SAA-C03)

**Question:**

A logistics company publishes parcel-scan events to Amazon Kinesis Data Streams. Each event contains a globally unique scan ID and a warehouse ID. If a producer times out, it can publish the same scan again with the same scan ID. An AWS Lambda consumer increments a warehouse's processed-parcel counter in Amazon DynamoDB for each event.

Occasionally, a Lambda invocation fails after a database write succeeds, causing records to be processed again. The company requires every unique scan to increase the counter exactly once, including during producer retries and consumer recovery. Processing must continue to support concurrent invocations.

Which solution meets these requirements?

**Correct answer:** Use a DynamoDB transaction to conditionally create a processed-event item keyed by the scan ID and increment the warehouse counter atomically. Retain the processed-event items and treat a condition failure caused by an existing scan ID as an already completed event.

**Explanation:** The stable scan ID identifies the same logical event across both producer retries and consumer recovery. The transaction commits the marker and counter increment together or commits neither. Concurrent or repeated attempts cannot apply the increment again because the conditional creation fails once the scan has been processed.

### Question 10 (ANS-C01)

**Question:**

A company uses AWS CloudFormation to deploy application VPCs. Before deploying application resources, each stack must configure an on-premises firewall with the VPC's approved CIDRs. The firewall has no supported CloudFormation resource type. Its API applies changes asynchronously and provides a job-status endpoint. Jobs complete within 5 minutes.

An existing Lambda function has connectivity to the firewall API and the CloudFormation custom resource response URL. The firewall supports creating or updating a rule set by a caller-supplied unique key. Repeating an operation with the same key and desired configuration does not create duplicate rules.

The deployment must not proceed until the firewall confirms that the configuration is applied. Stack updates must modify the same rule set without subsequently deleting it, and stack deletion must remove that stack's rule set. Which solution meets these requirements?

**Correct answer:** Implement a Lambda-backed custom resource that uses a stable rule-set key and PhysicalResourceId derived from the stack ID and logical resource ID. Handle Create and Update by ensuring the requested configuration exists and polling until the firewall job succeeds before sending SUCCESS. Handle Delete by removing that rule set. Configure sufficient Lambda and custom resource timeouts, and make application resources depend on the custom resource.

**Explanation:** A custom resource integrates the external firewall into the stack lifecycle. Waiting for confirmed job completion prevents dependent resources from deploying prematurely. A stable PhysicalResourceId avoids replacement-related deletion during updates, while a stable rule-set key makes repeated configuration requests safe. The Delete handler removes only the stack-owned rule set.

## Practice Idempotency in a full exam

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

- [DOP-C02](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional): 15 questions
- [SAA-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate): 13 questions
- [SAP-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional): 11 questions
- [DEA-C01](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate): 11 questions
- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 6 questions
- [SOA-C03](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate): 5 questions
- [ANS-C01](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty): 5 questions
- [SCS-C03](https://blowstack.com/practice-exams/aws-certified-security-specialty): 4 questions
- [DVA-C02](https://blowstack.com/practice-exams/aws-certified-developer-associate): 4 questions
- [MLA-C02 (beta)](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate): 3 questions

## What is Idempotency

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.

- MLA-C02 (beta): Idempotency: retry-safe streaming transformations (Premium), https://app.blowstack.com/lessons/idempotency-retry-safe-streaming-transformations-mla-c02
- SAP-C03: Idempotency vs At-Least-Once Delivery (Premium), https://app.blowstack.com/lessons/idempotency-vs-at-least-once-delivery-sap-c03
- SOA-C03: Idempotency: retry-safe runbook actions (Premium), https://app.blowstack.com/lessons/idempotency-retry-safe-runbook-actions-soa-c03
- AIP-C01: Idempotency: retry-safe vector store updates (Premium), https://app.blowstack.com/lessons/idempotency-retry-safe-vector-store-updates-aip-c01
- DEA-C01: Idempotency: replay-safe data ingestion (Premium), https://app.blowstack.com/lessons/idempotency-replay-safe-data-ingestion-dea-c01
- SCS-C03: Idempotency: retry-safe remediation actions (Premium), https://app.blowstack.com/lessons/idempotency-retry-safe-remediation-actions-scs-c03
