Skip to main content
miji.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.

Was this article helpful?

Related Terms

URL Shortener Architecture

The internal design of a URL shortening service, covering ID generation, database design, caching strategy, and redirect handling.

API Key

A unique string used to authenticate and control access to a web API. Identifies the caller and enforces usage limits.

API Rate Limit

A restriction on the number of API requests a client can make within a specified time period.

Base62 Encoding

An encoding scheme that represents data using 62 alphanumeric characters (a-z, A-Z, 0-9). Widely used to generate short URL codes.

URL Normalization

The process of converting multiple URLs that point to the same resource but differ in notation into a single standardized form. Essential for preventing duplicate content issues.

307 Redirect

A temporary HTTP redirect that preserves the original request method, ensuring POST requests are not converted to GET.

Related Articles

URL Shortener API Guide - Generating Short URLs Programmatically

A practical guide to using URL shortener APIs. Learn about request formats, response structures, authentication, and implementation patterns.

How URL Shorteners Work - The Technical Side of Redirects

Discover the technical mechanics behind URL shortening: hash generation, database lookups, HTTP redirects, and more. Includes HTTP response examples and base-62 encoding calculations.

GitHub Short URLs - Shorten Long Issue, PR, and Blob URLs for Developer Workflows

Manage GitHub long Issue, PR, and blob URLs with short links. Streamline code reviews, documentation, and team communication with custom short URLs.

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