In computer science, idempotency is a property of an operation where applying it multiple times has the same final effect as applying it just once. If you send the same request to a server five times, an idempotent system ensures that the outcome on the server doesn't change after the first successful attempt.
Beyond ensuring the same result, a key characteristic of idempotent operations is that they produce no side effects with additional calls. This is a core requirement for building resilient distributed systems where intermittent network outages or timeouts might cause a client to send the same message more than once.
Analogy: Think of the "up" button on an elevator. If you press it once, the elevator is called to your floor. If you press it ten more times while waiting, the result is the same—one elevator still comes to your floor. Pressing the button multiple times doesn't summon ten separate elevators. In contrast, adding an item to a digital shopping cart is usually not idempotent. If you click the "Add to Cart" button five times, you’ll likely end up with five of that item in your basket.
Safely retry requests after a timeout or connection drop without fear of duplicating actions (like double-charging a credit card).
Users don't need complex state tracking to know if a previous request succeeded; they can simply "retry until success."
Distributed systems can recover from crashes by replaying logs or re-sending missed messages without corrupting data.
The REST standard defines how different types of web requests should behave. Some HTTP methods are naturally "safe" or idempotent by design, meaning the specification expects them to behave predictably even when repeated. Others are designed to create new data and require extra care to make them safe for retries.
According to RFC 9110, several standard methods are inherently idempotent. Repeating these actions should not change the state of the server beyond the initial request.
Some methods are not idempotent because their primary job is to change data in a way that creates something new or modifies a portion of an existing record.
Idempotency is often needed in the systems we build. In some cases, it is handled for us. In other cases, we as developers need to take action to make it happen.
The most famous example is the "double charge" problem. If a user’s browser hangs while they are paying for a flight, they might click "Pay" again. A payment API that uses an idempotency key ensures that the second click is recognized as a retry. This protects the customer's bank account and reduces the operational cost of handling refunds for duplicate transactions.
Tools like Terraform and Ansible rely on idempotence. When you run a script to "create a 10GB storage bucket," the tool checks the current state of your cloud.
Modern web APIs often implement the Idempotency-Key header (now a standardized IETF draft) to allow developers to build more robust integrations.
An "upsert" (update or insert) is a classic idempotent database operation. Instead of a simple "Insert," an upsert says: "If this record exists, update it; if not, create it."
Google Cloud provides several tools that make implementing these patterns easier for developers. Building on a managed platform reduces the amount of "boilerplate" code you need to write to keep your data safe.

