C# Interview Question #188

What is idempotency in web APIs?

Testing, Security, APIs & Reliability Senior Advanced

Quick Interview Answer

An operation is idempotent when performing the same operation multiple times has the same intended effect on server state as performing it once.

Detailed Explanation

An operation is idempotent when performing the same operation multiple times has the same intended effect on server state as performing it once.

GET, PUT, and DELETE are defined as idempotent by HTTP semantics, although repeated responses can differ. POST is not inherently idempotent.

For payment, order, or job-creation endpoints, applications can implement idempotency keys so retries caused by network failures do not accidentally create duplicate operations.

Code Example

// Conceptual flow:
// 1. Client sends Idempotency-Key header.
// 2. Server checks whether the key was processed.
// 3. Existing result is returned for a duplicate key.
// 4. New operation is stored atomically with the key.