idempotency
The property of an operation that gives the same result whether you run it once or many times, because a repeat run finds nothing left to do.
In more detail
An idempotent operation checks the current state and acts only where it differs from what was asked, so repeating it is harmless. Appending a line to a file is not idempotent, because every run adds another copy, while "make sure this line is present" is. Idempotency is what makes it safe to retry after a failure or rerun on a schedule.
Examples
In Ansible idempotency lives in the modules: a second run of an idempotent playbook reports ok rather than changed for every task.The command module cannot know what a command did, so it reports changed every time.In HTTP, GET, HEAD, PUT and DELETE are idempotent and POST is not, so retrying a POST safely needs an idempotency key.Message consumers and webhook handlers must be idempotent because deliveries repeat.In AWS: The property that doing an operation twice has the same effect as doing it once.mkdir -p build # succeeds again and againrm -f "$tmp" # does not mind a missing fileIdempotent Kafka consumers make at-least-once delivery safe.For React components it means rendering again with the same props, state and context produces the same JSX, which is why Strict Mode can call components twice in development.terraform plan → No changes. Your infrastructure matches the configuration.In Terraform you see it when you plan a second time and it reports no changes, because the real infrastructure already matches the configuration. This is what makes it safe for a pipeline to run the same configuration on every commit. Scripts are usually not idempotent unless you add checks yourself.Related terms
- desired state — A description of how a machine should look when the work is finished, rather than a list of steps to get there.
- changed — The task result meaning the module ran and altered the host to make it match the description.
- ok — The task result meaning the module ran and the host already matched the description, so nothing was changed.
- command module — The module that runs any program you name on the host and reports what it printed, without being able to tell whether it changed anything.
- Ansible module — A small program that knows how to manage one kind of thing, such as a file, a package or a service, and that a task calls to do its work.
- safe method — An HTTP method, such as GET or HEAD, whose request is not meant to change anything on the server.
- idempotency key — A unique value a client sends with a non-idempotent request, such as a create, so the server can recognise a retry and return the original result instead of acting twice.
- retry — Sending a request again after it failed or timed out, in the hope that it succeeds the second time.
- idempotent consumer — A message or webhook handler that produces the same result whether it sees a message once or several times.
- event — A record of something that has already happened, such as task completed, with an identifier, a time, a type and its data.
- side effect — Anything a piece of code does besides returning a value, such as writing to a database, sending a message or changing a variable outside it.
- EXIT trap — A trap on the special name EXIT, whose handler runs whenever the shell exits: at the end, on exit, or when set -e stops it.
- mkdir — The shell command that makes a new directory; with -p it also makes missing parent directories and does not complain if the directory already exists.
- deduplication — Detecting and discarding repeated copies of the same message or request, usually by remembering identifiers already processed.
- upsert — A database write that inserts a row if it does not exist and updates it if it does, in one statement.
- at-least-once delivery — A delivery guarantee under which every message arrives, but some may arrive more than once.
- HTTP method — The verb at the start of a web request that says what the client wants, such as GET to read or POST to create.
- unique constraint — A constraint that no two rows may have the same value in a column or combination of columns.
- pure function — A function whose result depends only on its arguments and which has no side effects, so the same inputs always give the same output.
- Strict Mode — A development-only React wrapper that runs extra checks, such as rendering components twice and running every Effect setup and cleanup an extra time.
- declarative — A style where you describe the end result you want and let the tool work out the steps to get there.
- terraform plan — The command that compares configuration, state and reality and prints the actions needed to make them match, without changing anything.
Taught in
- When The Call Fails — AI Engineering: LLM Apps, RAG & Agents
- Agent SDKs And Human Approval — AI Engineering: LLM Apps, RAG & Agents
- What Configuration Management Is — Ansible Configuration Management at Scale
- Your First Ad Hoc Command — Ansible Configuration Management at Scale
- Connections And Privilege Escalation — Ansible Configuration Management at Scale
- Writing Your First Playbook — Ansible Configuration Management at Scale
- Modules And Idempotency — Ansible Configuration Management at Scale
- Handlers And Notify — Ansible Configuration Management at Scale
- Templates With Jinja — Ansible Configuration Management at Scale
- Error Handling With Block, Rescue And Always — Ansible Configuration Management at Scale
- Performance, Forks And Best Practices — Ansible Configuration Management at Scale
- HTTP Methods And Status Codes — Modern API Architecture: REST, GraphQL & gRPC
- Actions That Do Not Fit CRUD — Modern API Architecture: REST, GraphQL & gRPC
- Error Handling And Safe Retries — Modern API Architecture: REST, GraphQL & gRPC
- Idempotency Keys — Modern API Architecture: REST, GraphQL & gRPC
- Event-Driven Architecture And Queues — Modern API Architecture: REST, GraphQL & gRPC
- Decoupling: SQS, SNS, EventBridge And Step Functions — AWS Certified Solutions Architect – Associate (SAA-C03) Exam Prep
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation
- Seven Steps Called GitOps: The Declarative Principle — Certified GitOps Associate (CGOA) Exam Prep
- An Hour Without Payments: Continuously Reconciled — Certified GitOps Associate (CGOA) Exam Prep
- Serverless Compute (Lambda) — Cloud Infrastructure & Hyperscaler Architecture
- Two Reminders, One Booking: Integration And DevOps Tools — CompTIA Cloud+ (CV0-004) Exam Prep
- DevOps Sprint: Tax At A Hundred Percent — CompTIA Cloud+ (CV0-004) Exam Prep
- The Payment That Was Charged Twice — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Ninety Minutes, No Question Count — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- The Retry That Overtook — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Two Copies Of One Service — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Too Slow Between Two Polls — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Two Brokers Down — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Retry and Circuit Breaker Policies with Polly — Modern .NET Core, C# & Enterprise Microservices
- Asynchronous Event Processing: Outbox Pattern & Queues — Production Full-Stack Engineering
- Idempotent Producers And Retries — Apache Kafka & Event Streaming
- At Most Once, At Least Once — Apache Kafka & Event Streaming
- Duplicates Are The Default — Apache Kafka & Event Streaming
- Idempotent Consumers And Deduplication Keys — Apache Kafka & Event Streaming
- Headers, Envelopes And Event Metadata — Apache Kafka & Event Streaming
- Namespaces, Labels And Declarative Manifests — Kubernetes: Production-Grade Container Orchestration
- A Tiny CRD, Controller And The Operator Pattern — Kubernetes: Production-Grade Container Orchestration
- JSX Transpilation: createElement, JSX Runtime, React Elements — React 19 & Modern Component Architecture
- Component Purity: Pure Functions, Idempotence And Side Effects — React 19 & Modern Component Architecture
- Eventual Consistency And What It Costs A Product — Scalable System Design & Distributed Architecture
- Idempotency, And Exactly Once As A Fiction — Scalable System Design & Distributed Architecture
- Load Balancing And The Failure Modes It Introduces — Scalable System Design & Distributed Architecture
- Retries, Backoff And Jitter — Scalable System Design & Distributed Architecture
- Monolith Versus Services: The Honest Trade Offs — Scalable System Design & Distributed Architecture
- Observability As A Design Input — Scalable System Design & Distributed Architecture
- Worked Design One: Ticket Booking, Correctness First — Scalable System Design & Distributed Architecture
- Worked Design Two: A Global Chat System — Scalable System Design & Distributed Architecture
- Worked Design Three: A Metrics Ingestion Pipeline — Scalable System Design & Distributed Architecture
- What Is Infrastructure As Code? — Infrastructure as Code with Terraform
- Predicting Changes, Then Applying Them — Infrastructure as Code with Terraform
- Infrastructure As Code, And One Workflow For Every Platform — HashiCorp Terraform Associate (004) Exam Prep
- Write, Plan, Apply, And What Init Prepares — HashiCorp Terraform Associate (004) Exam Prep
- Forty Servers By Teatime: Ansible Playbooks, Inventories And Puppet Manifests — CompTIA Linux+ (XK0-006) Exam Prep
- Graded On A Machine You Never Touched — RHCE in Ansible (EX294): Automate Red Hat Systems
- Anatomy Of A Playbook: Plays, Tasks And Modules — RHCE in Ansible (EX294): Automate Red Hat Systems
- Facts And Magic Variables: Let Each Node Describe Itself — RHCE in Ansible (EX294): Automate Red Hat Systems
- Deploying Files: file, copy, lineinfile And blockinfile — RHCE in Ansible (EX294): Automate Red Hat Systems
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
- Handlers And Failure: notify, block, rescue And always — RHCE in Ansible (EX294): Automate Red Hat Systems
- Packages And Repositories: yum_repository And dnf — RHCE in Ansible (EX294): Automate Red Hat Systems
- Services And Boot Targets: Started Is Not Enabled — RHCE in Ansible (EX294): Automate Red Hat Systems
- Storage: Partitions, Volume Groups And Volumes Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems
- Archives: archive And unarchive On The Managed Nodes — RHCE in Ansible (EX294): Automate Red Hat Systems
- Scheduling: cron Jobs With Names, And Timers — RHCE in Ansible (EX294): Automate Red Hat Systems
- SELinux: Labels, Ports And Booleans That Persist — RHCE in Ansible (EX294): Automate Red Hat Systems
- Users And Groups From A List, With Passwords That Settle — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: A Web Node From A Ticket — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: People, Passwords And sudo From The Vault — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 1: Seven Tasks Across Three Sections — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 2: Real Machines And The Patterns That Fail — RHCE in Ansible (EX294): Automate Red Hat Systems
References
- Ansible glossary: idempotency
- Ansible concepts: modules
- RFC 9110: HTTP Semantics, section 9.2.2 Idempotent methods
- MDN: Idempotent
- Amazon Builders’ Library: Making retries safe with idempotent APIs
- Bash Reference Manual: Bourne Shell Builtins (trap)
- Enterprise Integration Patterns: idempotent receiver
- RFC 9110: idempotent methods
- microservices.io: Idempotent consumer
- React: Keeping components pure
- React reference: Components and Hooks must be idempotent
- RFC 9110: idempotent methods
- What is Terraform?
Certification courses
- AWS AIP-C01 course and practice exam: AI engineering with LLM apps, RAG and agents
- AWS Solutions Architect Associate course and practice exam: SAA-C03
- CGOA course and practice exam: Certified GitOps Associate
- CompTIA Cloud+ course and practice exam: CV0-004
- CCDAK and CCAAK course and practice exams: Confluent Apache Kafka certifications
- Terraform Associate course and practice exam: HashiCorp Terraform Associate (004)
- CompTIA Linux+ course and practice exam: XK0-006
- RHCE course and practice exam: Red Hat Certified Engineer in Ansible (EX294)