Skip to main content
短.be

Idempotency

The property that performing the same operation multiple times produces the same result as performing it once. Essential in API design for safely handling duplicate requests.

Aug 25, 2026 · About 1 min read

URL Shortening

Idempotency is the property that executing an operation once or multiple times yields the same outcome. In mathematics it is expressed as f(f(x)) = f(x). In web API design, idempotency ensures that retrying a request after a network failure or timeout does not cause unintended side effects such as duplicate records or double charges.

HTTP methods have defined idempotency characteristics. GET, PUT, and DELETE are idempotent, while POST is non-idempotent (each call may create a new resource). Idempotent here means that the effect on the server of sending the same request several times is the same as sending it once. The responses need not be identical: a first DELETE typically returns 200, and later ones often return 404 because the target is already gone, which does not break idempotency.

For a URL shortening API, idempotency is a core design question. If the same long URL is submitted twice, should two different short URLs be created, or should the same short URL be returned both times? An idempotent design returns the same short URL for the same input, preventing duplicates when a client retries after a network error.

A common implementation technique is the idempotency key. The client attaches a unique key (typically a UUID) to each request. The server caches the result for that key. If the same key appears again, the server returns the cached result without re-executing the operation. Stripe's payment API is a well-known example of this pattern.

In URL shortening services, idempotency is often combined with URL normalization. The input URL is normalized, a hash is computed, and the same hash always maps to the same short code. This also means that "https://example.com/page" and "https://example.com/page/" resolve to the same short URL.

Share on XHatena

Was this article helpful?

Related Terms

Related Articles

FAQ

Why do APIs need idempotency?
Network failures and timeouts cause clients to retry requests. Without idempotency, retries can trigger duplicate processing - double charges, duplicate records, and so on. With idempotency, retries are safe because the result is always the same.
How is an idempotency key implemented?
The client sends a UUID in a request header (e.g., Idempotency-Key: 550e8400-...). The server caches the result in Redis or a similar store, keyed by that UUID. If the same key arrives again, the server returns the cached result without re-executing the operation.
Are GET requests always idempotent?
In the HTTP specification GET is not only idempotent but also safe, meaning it carries read-only semantics. Servers are still allowed to update access logs or statistics; the point is that a client issuing a GET is not requesting any change of state. Browser prefetching, crawlers, and caches all send GET requests on that assumption, so a GET endpoint that modifies data will have its changes triggered at moments nobody intended. Use POST, PUT, or DELETE when the state has to change.

Put the terms to work

Shorten a URL for Free