Back to all questions

What is idempotency?

System designMiddleSenior
Seen on interview:2 users

So, let’s start with the definition of idempotency. It’s a concept that guarantees that repeating an operation multiple times has the same effect as performing it once. Most often, this question comes up in the context of REST API design, so it makes sense to discuss this concept in terms of HTTP methods.

For example, let’s look at the PUT method

According to REST, it performs a full update of a resource. And if we send it 10 times with the same body, all those calls will produce the same result as a single call.

The same applies to GET, DELETE, and PATCH. But if we look at the POST method, according to the REST concept, each call creates a new record in the database, so repeating the call will NOT have the same effect - therefore, the method is not idempotent. Additionally, I’d recommend reading about idempotency in distributed systems and talking about it in an interview. It’s also good practice to mention an idempotency key and give an example of how it’s used.

Seen on interview?

Comments (0)

Sign in to leave a comment

No comments yet. Be the first!