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
7
votes
2 answers

If a GET request's response changes, is idempotency respected?

I am reading a lot about rest API and I always stumble upon terms idempotency. Basically GET, HEAD, PUT, DELETE and OPTIONS are all idempotent, and POST is not. This statement on http://www.restapitutorial.com/lessons/idempotency.html made me doubt…
mko
  • 6,638
  • 12
  • 67
  • 118
7
votes
2 answers

On the idempotence of GET

I have been doing some reading on the GET HTTP method and in particular on its idempotent quality. This is my understanding: if I call a GET operation 1 time or a million times (or any number of times) the result should be the same. My problem…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
6
votes
2 answers

Cloud functions and Firebase Firestore with Idempotency

I'm using Firestore at beta version with Cloud Functions. In my app I need to trigger a function that listens for an onCreate event at /company/{id}/point/{id} and performs an insert (collection('event').add({...})) My problem is: Cloud Functions…
6
votes
4 answers

How can I get the installed YUM packages with Ansible?

I am trying to get all the installed YUM packages on an RHEL machine. I can easily get it through using shell commands which is not idempotent and would like to use the YUM command instead. The shell command works fine: - name: yum list packages …
user_dev
  • 1,357
  • 3
  • 20
  • 46
6
votes
1 answer

How continuous Azure Web Jobs can be idempotent and send email?

After reading tons of information on the web about Azure WebJobs, documentation says a job should be idempotent, on the other hand, blogs say they use WebJobs to do actions such as "charging a customer", "sending an e-mail". This documentation says…
jsgoupil
  • 3,788
  • 3
  • 38
  • 53
6
votes
1 answer

Idempotent PUT in a concurrent environment

Context I have a REST API where multiple clients (applications) can update the state of a resource with PUT. For the example, this resource is a lamp that you can turn ON or OFF. This resource is also automatically updated by the system when it…
AilurusFulgens
  • 199
  • 1
  • 12
6
votes
4 answers

RESTful idempotence

I'm designing a RESTful web service utilizing ROA(Resource oriented architecture). I'm trying to work out an efficient way to guarantee idempotence for PUT requests that create new resources in cases that the server designates the resource key. From…
Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
6
votes
3 answers

How to rename resources in an idempotent manner?

I implemented an API that renames a company as follows: PUT /companies/A { "name": "B" } will return HTTP 301 with the Location header pointing at the company's new URI: /companies/B. How can I make this operation idempotent with and without…
Gili
  • 86,244
  • 97
  • 390
  • 689
6
votes
1 answer

Client side id generation strategy for REST web service

Let's say I want to build a REST service for making notes that looks something like this: GET /notes/ // gives me all notes GET /notes/{id} // gives the note identified by {id} DELETE /notes/{id} // delete note PUT /notes/{id} //…
Zounadire
  • 1,496
  • 2
  • 18
  • 38
5
votes
2 answers

What kind of DB operations are both "idempotent and commutative" at the same time?

I was researching Scala DB frameworks/wrappers, and came across Gizzard, from Twitter. While I was impressed at first, I cooled down when I read the restriction. They say that all DB operations you make have to be both idempotent and commutative. If…
Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85
5
votes
2 answers

How to handle the success URL on Stripe considering GET requests should be safe?

When we make a stripe checkout session we include a success url: session = await this.stripe.checkout.sessions.create({ payment_method_types: ['card'], line_items: lineItems, payment_intent_data: { transfer_data: { …
Dashiell Rose Bark-Huss
  • 2,173
  • 3
  • 28
  • 48
5
votes
2 answers

Sidekiq Idempotency, N+1 Queries and deadlocks

In the Sidekiq wiki it talks about the need for jobs to be idempotent and transactional. Conceptually this makes sense to me, and this SO answer has what looks like an effective approach at a small scale. But it's not perfect. Jobs can disappear in…
lobati
  • 9,284
  • 5
  • 40
  • 61
5
votes
2 answers

Ansible blockinfile module idempotent?

I want to insert some lines in a file using the blockinfile module. - name: add some lines blockinfile: dest: /etc/sysctl.conf block: | mykey1={{ kernvars['my_value1'] }} mykey2={{ kernvars['my_value2'] }} mykey3={{…
pkaramol
  • 16,451
  • 43
  • 149
  • 324
5
votes
7 answers

How can I prevent database being written to again when the browser does a reload/back?

I'm putting together a small web app that writes to a database (Perl CGI & MySQL). The CGI script takes some info from a form and writes it to a database. I notice, however, that if I hit 'Reload' or 'Back' on the web browser, it'll write the data…
Marty
  • 6,494
  • 3
  • 37
  • 40
5
votes
0 answers

SSMS 2012 - Data Only Script Generation With If Not Exists

I would like to generate a data only insert script within SSMS 2012 which contain the if not exists statements to make the scripts idempotent. Right clicking the database I wish to generate the script for and selecting Tasks -> Generate Scripts the…
Jpin
  • 1,527
  • 5
  • 18
  • 27
1 2
3
18 19