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 again
rm -f "$tmp"  # does not mind a missing file
Idempotent 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

Taught in

References

Certification courses