What is idempotency, and how do you design idempotent automation?
IntermediateConceptData formats, HTTP & REST APIs
Answer
An operation is idempotent if running it once or ten times leaves the system in the same state. It is what makes retries and re-runs safe.
- Check-then-act on desired state: "ensure tag
Owner=xexists", not "add tag". - Use APIs that are naturally idempotent (PUT,
put_bucket_tagging,kubectl apply). - Pass client tokens: many AWS create calls accept
ClientToken(run_instances,create_snapshotin some services) so a retried call does not create a second resource. - Treat "already exists" and "not found on delete" as success.
More on Data formats, HTTP & REST APIs
How do you read and write JSON, and what are the common gotchas?BeginnerWhy must you use `yaml.safe_load` rather than `yaml.load`?BeginnerHow do you load a multi-document Kubernetes YAML file?IntermediateHow do you read and write CSV files properly?BeginnerHow do you make an HTTP request with `requests` the right way?BeginnerWhy use a `requests.Session`?Intermediate