Author: Brandon Pearman

The views expressed here are mine alone and do not reflect the view of my employer.

A function is idempotent when immediate duplicate calls return the same result and the system state remains the same.

For Example:

Let's assume our database contains the following data:


        {
            "name": "Bob",
            "foods": ["Pizza", "Burger"]
        }
        

We then make a request With the following:

PUT /person


    {
        "name": "Bob",
        "foods": ["Oranges"]
    }

This request will change the data in the database to match that of the request

We then make the exact same request immediately after:

PUT /person


    {
        "name": "Bob",
        "foods": ["Oranges"]
    }

This request will not make any changes to the data because it has already been changed to that.

In other words the end state of the system is the same, whether you call this function once or three hunderd times.

Request Database

Intitial

["Pizza", "Burger"]

First request: ["Oranges"]

["Oranges"]

Duplicate request: ["Oranges"]

["Oranges"]

Duplicate request: ["Oranges"]

["Oranges"]

Check out these links for more info:

My design and architecture repo