Questions tagged [idempotent]

A function is said to be idempotent when it can be called multiple times without changing the result.

Idempotence is a property of certain function in mathematics or computer science. It states that the function can be applied multiple times without changing the result from the result of applying the function a single time.

Examples from mathematics

  • Multiplying some value by 1, or by 0; these should give the same result no matter how many times they are applied. I.e.:

    (x * 1) == (1 * (1 * x)) == (1 * (1 * (1 * x))) == ...

  • abs(x):

    abs(-3) == 3, but abs(3) == 3 too. Similarly abs(abs(-3)) == abs(abs(abs(-3))) ...

Examples from computer sience

  • HTTP-context: A GET-operation or a DELETE-operation; each of these should effect the same results each time. A counter-example could be a post-operation, which may result in a different outcome / state each time it is called (calling it multiple times may result in duplicate date being stored, for instance).
  • Setting a (boolean) flag; the resulting state should be the same whether you set it once or many times.
272 questions
1142
votes
18 answers

What is an idempotent operation?

What is an idempotent operation?
Will
  • 19,789
  • 10
  • 43
  • 45
213
votes
4 answers

Status code when deleting a resource using HTTP DELETE for the second time

Given that the DELETE verb in HTTP is idempotent, when I issue the following request, what should happen the second (or third, or fourth, etc...) time I make it? DELETE /person/123 The first time, the resource is deleted and I return a 204…
Craig Wilson
  • 12,174
  • 3
  • 41
  • 45
74
votes
6 answers

Are idempotent functions the same as pure functions?

I read Wikipedia's explanation of idempotence. I know it means a function's output is determined by it's input. But I remember that I heard a very similar concept: pure function. I Google them but can't find their difference... Are they equivalent?
Lai Yu-Hsuan
  • 27,509
  • 28
  • 97
  • 164
64
votes
3 answers

What are best practices for activation/registration/password-reset links in emails with nonce

Applications send out emails to verify user accounts or reset a password. I believe the following is the way it should be and I am asking for references and implementations. If an application has to send out a link in an email to verify the user's…
Kariem
  • 4,398
  • 3
  • 44
  • 73
48
votes
3 answers

What is the difference between an Idempotent and a Deterministic function?

Are idempotent and deterministic functions both just functions that return the same result given the same inputs? Or is there a distinction that I'm missing? (And if there is a distinction, could you please help me understand what it is)
sfletche
  • 47,248
  • 30
  • 103
  • 119
47
votes
1 answer

Does idempotency include response codes?

Do repeated requests to idempotent methods have to return the same response code? A lot of other people are asking the same question and ending up with contradicting answers. The answer should reference an authoritative source on the matter.
Gili
  • 86,244
  • 97
  • 390
  • 689
38
votes
3 answers

What does idempotent method mean and what are the side effects in case of calling close method of java.lang.AutoCloseable?

Java docs of close() method of java.lang.AutoCloseable says Note that unlike the close() method of Closeable, this close() method is not required to be idempotent. In other words, calling this close method more than once may have some visible…
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
38
votes
7 answers

Consequences of POST not being idempotent (RESTful API)

I am wondering if my current approach makes sense or if there is a better way to do it. I have multiple situations where I want to create new objects and let the server assign an ID to those objects. Sending a POST request appears to be the most…
mibollma
  • 14,959
  • 6
  • 52
  • 69
25
votes
1 answer

How is in Java the idempotence of the close() method of the Closeable interface ensured?

The Closeable interface was introduced in Java 5 whereas the AutoCloseable interface came in Java 7 together with the try-with-resources statement. Closeable extends (since Java 7) the Autocloseableinterface. In the book OCA/OCP Java SE 7 -…
Mathias Bader
  • 3,585
  • 7
  • 39
  • 61
23
votes
4 answers

Should IDisposable.Dispose() implementations be idempotent?

The Microsoft.NET framework provides the IDisposable interface which requires an implementation of void Dispose() method. Its purpose is to enable manual, or scope-based releasing of expensive resources an IDisposable implementation may have…
Ivaylo Slavov
  • 8,839
  • 12
  • 65
  • 108
21
votes
4 answers

Terraform: How to run remote-exec more than once?

I have noticed that terraform will only run "file", "remote-exec" or "local-exec" on resources once. Once a resource is provisioned if the commands in a "remote-exec" are changed or a file from the provisioner "file" is changed then terraform will…
Alex Cohen
  • 5,596
  • 16
  • 54
  • 104
18
votes
1 answer

ansible ignore the run_once configuration on task

I am using Ansible and I want to run a task only once. I follow the documentation about how to configure and run a task only once - name: apt update shell: apt-get update run_once: true But when I run Ansible, it always runs this task. How can…
Robert
  • 10,403
  • 14
  • 67
  • 117
16
votes
1 answer

REST API GET with sensitive data

I'm designing api with method that should be an idempotent, and should not modify any data on the server. It should be method that process request and return response for given parameters. One of the parameters is sensitive data. It's not an option…
Grandys
  • 163
  • 1
  • 1
  • 8
15
votes
3 answers

What's the correct way to view idempotency in terms of HTTP DELETE?

I have spent a lot of time recently reading the HTTP 1.1 specification and relating it to REST. I have found that there are two interpretations of the HTTP DELETE method in regards to its "idempotency" and safety. Here are the two camps: If you…
Daniel Crenna
  • 3,326
  • 1
  • 24
  • 34
13
votes
2 answers

How to make write operation idempotent?

I'm reading an article about the recently released Gizzard sharding framework by twitter (http://engineering.twitter.com/2010/04/introducing-gizzard-framework-for.html). It mentions that all write operations must be idempotent to ensure high…
Morgan Cheng
  • 73,950
  • 66
  • 171
  • 230
1
2 3
18 19