# Define Idempotent: What It Means, With Simple Examples

> What does idempotent mean? Learn the definition with simple math, code, HTTP and data pipeline examples, plus how to make reruns safe.

Source: https://www.erathos.com/en/blog/define-idempotent
Em português: https://www.erathos.com/blog/define-idempotent
Published: 2026-11-04
Category: Data Engineering

![Define Idempotent](https://cms-media.erathos.com/Define Idempotent.png)

Suppose you have a data job that loads yesterday's orders, and it fails right near the end. If the job is idempotent, then when someone reruns it, the orders table will end up exactly as if the job had succeeded the first time. If the job isn't idempotent, some of the orders will now appear twice in the orders table, and the revenue report will be wrong.

The word "idempotent" started in mathematics, but it is now common in software, where it describes which web requests can safely be retried automatically by the application and which data jobs can safely be retried by humans without any cleanup required.

## What does idempotent mean?

An idempotent operation has the same effect, no matter whether it's performed once or many times. For instance, pressing the call button of an elevator five times has the same effect as pressing it once: one elevator will come.

The word is pronounced "EYE-dem-POH-tent" ([Merriam-Webster](https://www.merriam-webster.com/dictionary/idempotent) says ˈī-dəm-ˌpō-tᵊnt). It was [coined in 1870](https://en.wikipedia.org/wiki/Idempotence) by the American mathematician Benjamin Peirce. It comes from the combination of the two Latin words idem (meaning same) and potent (meaning power), so it literally means "the same power". Peirce used the word to describe algebraic quantities that didn't change when they were raised to some power.

In math, a function f is idempotent when applying it twice gives the same answer as applying it once:

`f(f(x)) = f(x)`

The absolute value function:

Now we can generalize this pattern for software: instead of a "function" as an input, we have a "function" as an action. A web request, a job, a write to a database. The first time we run it, something changes, and then subsequent runs leave things unchanged.

## Idempotent examples from everyday life and math

The quickest test is simple. Do the thing once and write down the result. Then do it again on that result and compare:

Action

After once

After again

Idempotent?

Absolute value of -11

11

11

Yes

Rounding 4.7 down (floor)

4

4

Yes

Taking the larger of x and 5, with x = 2

5

5

Yes

Combining the set {1, 2} with itself

{1, 2}

{1, 2}

Yes

Squaring 1

1

1

Yes

Squaring 2

4

16

No

Adding 1 to 10

11

12

No

Pressing the elevator call button

One elevator on its way

Still one elevator

Yes

Pressing the elevator "door open" button

Door stays open

Door stays open longer

No

[Only 0 and 1 are idempotent whole numbers](https://en.wikipedia.org/wiki/Idempotence) when multiplying them: 0 × 0 = 0 and 1 × 1 = 1. Floor, ceiling and absolute value are some idempotent functions. The “door open” button is not idempotent because pressing it once adds more delay than pressing it zero times, and pressing it twice adds even more delay.

But wait. What if we chain two idempotent operations? Is the combination idempotent too? Let’s try: “the larger of x and 5” and “the remainder after dividing by 3”. Both are idempotent on their own. Now let’s chain them up and start with 7. Larger of 7 and 5 is 7. 7 divided by 3 has a remainder of 1. Let’s repeat the chain with 1. Larger of 1 and 5 is 5. 5 divided by 3 has a remainder of 2. Oops! The second run changed the answer. [The chained operations are not idempotent](https://en.wikipedia.org/wiki/Idempotence). This means we still need a rerun test for the whole data job, even if we know that the individual steps are idempotent.

## Idempotent code: setting a value vs adding to it

Code follows the same rule. Setting a value is idempotent, and adding to a value is not. This short Python script calls each kind of function three times, the way a retry might:

`def add_one(value):`
`    return value + 1`


`def set_balance(account, amount):`
`    account["balance"] = amount`


`def deposit(account, amount):`
`    account["balance"] += amount`


`print("add_one(10): once =", add_one(10), "; twice =", add_one(add_one(10)))`
`print("abs(-11): once =", abs(-11), "; twice =", abs(abs(-11)))`

`account = {"balance": 0}`
`for _ in range(3):`
`    set_balance(account, 100)`
`print("set_balance(100) called 3 times: balance =", account["balance"])`

`account = {"balance": 0}`
`for _ in range(3):`
`    deposit(account, 100)`
`print("deposit(100) called 3 times: balance =", account["balance"])`

Output:

`add_one(10): once = 11 ; twice = 12`
`abs(-11): once = 11 ; twice = 11`
`set_balance(100) called 3 times: balance = 100`
`deposit(100) called 3 times: balance = 300`

`set_balance` can be executed once or a hundred times and the balance remains 100. `deposit` adds 100 with each execution, meaning that two retries would result in three deposits. This matters in cases like network call timeouts where the caller can’t be sure if the first try succeeded or not. With a “set” action, the caller can just try again, but with an “add” action, a retry could mean double paying the customer.

## Which HTTP methods are idempotent?

The GET, HEAD, OPTIONS, TRACE, PUT and DELETE methods are idempotent. POST is not. PATCH is not guaranteed to be. A method is considered to be idempotent if [many identical requests have the same intended effect on the server as one request](https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods).

Here is the full list from the HTTP standard, plus PATCH:

Method

Safe (read-only)

Idempotent

GET

Yes

Yes

HEAD

Yes

Yes

OPTIONS

Yes

Yes

TRACE

Yes

Yes

PUT

No

Yes

DELETE

No

Yes

POST

No

No

PATCH

No

[Not guaranteed](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent)

CONNECT

No

No

In contrast, PUT is idempotent because its purpose is to "store this exact thing here". Thus if you send the request twice, it will result in the same thing being stored at the same place. POST often means "add a new one", and thus if you send `POST /add_row` 3 times, [it will result in 3 rows being added](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent).

The concept of idempotence is defined on the level of the effects on the server's data. It does not dictate what the server's response to the client must be. Thus, the first DELETE of a record may result in a 200, whereas the subsequent ones result in a 404, but both have the same result of the record being gone. It also doesn't preclude the server from recording each request in its logs on a separate line.

The importance of idempotent operations is that they can be re-sent by software without asking the user first. A client [should not retry non-idempotent requests](https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods) automatically, unless it has a way to determine that the request is safe to repeat. A proxy must not retry them. For example, a POST request can create an order, and a blind retry of the request can create a second order.

To allow clients to use idempotence on APIs that charge cards or create resources, many APIs use the concept of an idempotency key. The client can create a unique ID for the action it is taking, and send it as part of the request. Subsequent requests with the same ID can be answered with the result of the first request, avoiding performing the same operation twice. For example, the [Stripe API](https://docs.stripe.com/api/idempotent_requests) for card payments works like this:

- The client generates the key. Stripe recommends using random V4 UUIDs. A key can be up to 255 characters long.
- Stripe will save the status code and the body of the first request made with the idempotency key. A retry of the request will result in the saved response being returned. This is true even if the first request returned an error.
- Stripe can remove keys that are at least 24 hours old.
- If the same key is reused with different parameters, Stripe will return an error.

The AWS API can also make use of a caller-supplied ID. Without the ID, [a failed request to create an EBS storage volume may result in two volumes being created](https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/) instead of the single one that the caller wanted.

With the idempotency key, the whole retry flow looks like this:

## Why idempotency matters in data pipelines

Many schedulers (like Airflow) have some form of [task failure retry](https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html). This means that any task in a pipeline might execute on a given data set multiple times, due to some sort of temporary issue (a source API times out, the warehouse connection drops, etc.).

A classic failure pattern would be to run a sync, insert some batch of rows, and fail before saving your place (e.g. the last ID or timestamp read, i.e. the cursor). On the next rerun, we’ll start from our last known place, thus processing some rows for a second time.

Now let’s look at how that looks with each approach to writing data:

Whether that creates duplicates depends on how the job writes. This script loads the same three orders three times into two tables. One table gets a plain INSERT. The other gets an upsert, which inserts a row or updates it if a row with that ID already exists:

`import sqlite3`

`INSERT_SQL = "INSERT INTO orders_insert (id, amount) VALUES (?, ?)"`
`UPSERT_SQL = """\`
`INSERT INTO orders_upsert (id, amount) VALUES (?, ?)`
`ON CONFLICT(id) DO UPDATE SET amount = excluded.amount`
`"""`

`batch = [(1, 50.0), (2, 20.0), (3, 75.0)]`
`connection = sqlite3.connect(":memory:")`
`with connection:`
`    connection.execute("CREATE TABLE orders_insert (id, amount)")`
`    connection.execute("CREATE TABLE orders_upsert (id INTEGER PRIMARY KEY, amount)")`
`    for _ in range(3):`
`        connection.executemany(INSERT_SQL, batch)`
`        connection.executemany(UPSERT_SQL, batch)`

`insert_count = connection.execute("SELECT COUNT(*) FROM orders_insert").fetchone()[0]`
`upsert_count = connection.execute("SELECT COUNT(*) FROM orders_upsert").fetchone()[0]`
`print("Plain INSERT after 3 batch loads: row count =", insert_count)`
`print("UPSERT after 3 batch loads: row count =", upsert_count)`
`connection.close()`

Output:

`Plain INSERT after 3 batch loads: row count = 9`
`UPSERT after 3 batch loads: row count = 3`

The INSERT table has 9 rows for 3 orders, so total revenue is three times higher than it should be. The upsert table has 3 rows no matter how many times the batch runs because of its primary key, which uniquely identifies each order.

There are three typical ways to achieve idempotency when loading data:

1. Upsert or merge on a unique key. This approach is recommended by the Airflow guide, which tells us to [replace INSERT with UPSERT](https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html) when tasks are rerun. dbt also uses this approach for its incremental models when we supply a `unique_key`. [Instead of only appending new rows](https://docs.getdbt.com/docs/build/incremental-models), the unique key is used to update existing rows. Without a unique key, most data warehouses would only append new rows to existing tables.
2. Overwrite a fixed slice of data. A job that rebuilds a day of data (a partition) or even the entire table will always result in the same data after running.
3. Pin the time window of a job. A job that uses its scheduled date instead of the current system time will process the same day’s worth of data even when rerun next week.

## Idempotent vs safe, pure, deterministic and nullipotent

Several words sound close to idempotent and get mixed up with it. This is how they differ:

Term

What it means

Example

Idempotent

Doing it again changes nothing after the first time

PUT, DELETE, absolute value

Safe (HTTP)

The request only reads and changes nothing on the server

GET, HEAD

Nullipotent

It has no effect at all, even the first time

Reading a row from a table

Pure function

No side effects, and the same input always gives the same output

x + 1

Deterministic

The same input always gives the same output

x + 1

Every safe method is idempotent, but [PUT and DELETE are idempotent without being safe](https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods). [Nullipotent](https://en.wikipedia.org/wiki/Idempotence) operations (like reading) are the strongest cases, where even the first operation doesn't change state.

x + 1 is pure and deterministic but still not idempotent because feeding the result into the function again produces a different result.

## How Erathos handles reruns

Erathos moves data from databases, SaaS apps and APIs into your data warehouse. What a rerun does to each destination table depends on the [sync type](https://docs.erathos.com/platform/connections/sync-types) you pick for it:

Sync type

What it does

Duplicates after a rerun?

Full Refresh

Reads the whole source table and overwrites all values in the destination

No

Partial Overwrite

Inserts new records, and updated records overwrite the outdated ones

No

Partial Append

Inserts every record, so an updated record exists in both its old and new form

Yes, on purpose

Partial Versioned

Inserts every record and flags which one is the most recent version

Old versions stay, flagged

Partial syncs on the other hand only fetch records after a cursor. This is usually the creation date, the update date or an ID. To run a partial sync you need to provide a primary key and a date/datetime column for the cursor. Erathos proposes Partial Overwrite as the default sync type on the platform. There are three types of partial syncs, as explained in the docs:

With Partial Append and Partial Versioned, all versions are kept on purpose. These types are meant for use cases where you need a history of changes. You then use queries to get the most recent row.

There are also a couple of additional settings in Erathos to help deal with any errors or inconsistencies that could occur:

- Enable Full On: schedules regular full syncs to fix any inconsistencies between the source and destination
- [Custom retry strategy](https://docs.erathos.com/platform/connections/custom-retry-strategy): this setting (available in the PRO and Enterprise plans) configures how many times Erathos should attempt to retrieve the data before raising an error and sending an alert, with configurable pauses in between attempts

Note that when running a sync with a cursor, rows deleted from the source are not deleted from the destination, because there is no way for the sync to know about these deleted rows (they won’t be retrieved when fetching records after the cursor). Read [this article](https://www.erathos.com/en/blog/cursor-based-sync-vs-change-data-capture?utm_source=blog&utm_medium=organic&utm_content=bydefault&utm_campaign=define-idempotent) to learn about reading the database's change log, which is a solution for detecting deleted rows.

## FAQ

**What is the simplest way to define idempotent?** An action is idempotent if, when you do it again, the end state will be the same as if you did it once. This can be expressed in math as f(f(x)) = f(x).

**Is GET idempotent?** Yes, in the HTTP standard GET is both safe and idempotent. This is because GET only retrieves data.

**Is POST idempotent?** No, POST requests generally create resources. Doing three POSTs could create three records. However, some APIs (like Stripe’s) allow the client to specify an idempotency key, which makes it safe to retry POSTs.

**Is PUT idempotent?** Yes, PUT replaces the resource with the exact data you send. Sending the same data again will result in the same state.

**What is the difference between safe and idempotent?** Safe means the request doesn’t change anything. Idempotent means repeating it doesn’t change anything more than the first time. Safe methods are idempotent, and DELETE is idempotent but not safe.

**Does idempotent mean the response is always the same?** No, for example a second DELETE might return 404 instead of 200. Idempotence only refers to the end state of the data. And the server can still log every request.

**How do I make a data pipeline idempotent?** Write with an upsert or merge on a primary key, or overwrite a fixed slice (e.g. one day) of data. Use the scheduled date of the run for the time window. Then rerun the whole job on the same data and verify row counts don’t change.

## Try Erathos free for 14 days

Choose a sync type per table and see what a rerun does to your warehouse. [Try Erathos free for 14 days](https://app.erathos.com/signup?utm_source=blog&utm_medium=organic&utm_content=bydefault&utm_campaign=define-idempotent).
