Building Idempotent REST API

Fareed Rezaei
6 min readJul 15, 2021
Photo by Jeffrey Hamilton on Unsplash

Network latency and reliability is a major issue when it comes to making RESTful application. In ideal world, when a network call is made by the client, the server receives the call and processes it before responding to the request. The client receives a response and everything is done like charm!

However, we don’t live in an ideal world where everything work as expected. The same applies to the network calls; they are not reliable. A latency in the call can make, the browser assumes the call is lost and makes another call. This is called a Retry. With retries, we face a situation where two calls are sent and we are not sure if the server receives a single or both calls.

In another similar scenario, the user might be impatient and makes another call resulting in multiple calls sent to the server (Forced retry). We cannot expect the client to not have this behavior.

So what we want to make sure of, is the server side not being affected regardless of how many requests are sent to the server. This approach is called Idempotence or Idempotency.

A RESTful API is idempotent if the state of the server is not affected by multiple unintentional calls.

Now, in the RESTFul APIs, GET, PUT, DELETE operations are idempotent by design. This means, sending a get request multiple times will result in the same…

--

--

Fareed Rezaei
Fareed Rezaei

Written by Fareed Rezaei

15 years Software Engineer and Founder of 2 startups. I write about technology, cloud, and career advice

No responses yet