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

How to ensure idempotency in a Django REST API?

Say, I'm building a REST API based on Django/DRF and PostgreSQL. I want all GET, PUT, DELETE endpoints to follow the best practices and be idempotent. How can I ensure/verify that this is true?
planetp
  • 14,248
  • 20
  • 86
  • 160
3
votes
1 answer

How to have idempotent guarantee when writing spark dataset to hdfs?

I have a spark process that writes to hdfs (parquet files). My guess is that by default, if spark has some failure and retry, it could write some files twice (am I wrong?). But then, how should I do to get idempotence on the hdfs output? I see 2…
Juh_
  • 14,628
  • 8
  • 59
  • 92
3
votes
2 answers

Can http PUT modify the identifier?

In a Restful API: PUT /product/{id} Could the above http request, specify a different id in its body, so that to actually change the id of original record (assume the id is changable technically in the underling storage). This seems to vialotes the…
Eric
  • 22,183
  • 20
  • 145
  • 196
3
votes
1 answer

Is the Apache Camel - Idempotent Consumer Pattern implemented with a jdbcMessageIdRepository thread-safe?

I need to implement the idempotent consumer pattern in Camel (2.23.0) and was looking at possible implementations. Currently, I am only able to implement either the JdbcMessageIdRepository or JpaMessageIdRepository and was wondering if these…
Kim Zeevaarders
  • 732
  • 1
  • 7
  • 21
3
votes
4 answers

ansible change permissions using file module idempotent

I run my ansible playbooks through a cron job every night as I add to them every now and then. I want my output of each to only say changed=(num) if there is actually a change, but a few specific modules say changed when they were not changed at…
Dorilds
  • 418
  • 1
  • 7
  • 15
3
votes
1 answer

How to make a job idempotent that it's multiple runs produce the same resultant file in S3

I save a parquet file to S3 using spark df write. Scenario: I run Job1 and save xyz.parquet to S3 where my Job2 picks up xyz.parquet and loads data to DB. Now, I want the next time when I run Job1, it should generate xyz.parquet and load data to…
pallavik
  • 135
  • 2
  • 11
3
votes
2 answers

How can I get the installed apt packages with Ansible?

I am trying to list all installed packages on my Debian 7 (Wheezy), 8 (Jessie), and 9 (Stretch) machines. There are easy ways dealing with it using APT or dpkg, but I could not find a proper way to do this with Ansible out of the box. Is there a…
nicowde
  • 33
  • 1
  • 4
3
votes
0 answers

Xkb three key shortcut to acyclic switch keyboart layout like in Windows

The MS Windows introduced ability to switch current keyboard layout by press specific hotkey for each specific language. I found very comfortable to have acyclic shortcuts to switch layout to target language with following shortcuts: Alt+Shift+1,…
slonma
  • 115
  • 1
  • 5
3
votes
1 answer

Apache Camel RedisIdempotentRepository Configuration

Has anyone been able to successfully get RedisIdempotentRepository working in a Camel Route? My Camel Route is built using Java 8+, Apache Camel (2.17.1) and Spring Boot (1.3.3.RELEASE). The Camel Route loads and processes messages but does not…
Jeremy Deane
  • 131
  • 1
  • 6
3
votes
1 answer

Is a pure function idempotent?

Is every pure function idempotent? I wouldn't ask such a crazy question if I hadn't seen this statement in the official Angular.js tutorial: The filter function should be a pure function, which means that it should be stateless and idempotent.…
iman00b
  • 121
  • 4
3
votes
3 answers

How to build REST API with server-defined ids?

This is a classic RESTful way of creating resources I have in the application: # This creates user. Client is responsible to create UUID, which is simple PUT /users/CLIENT_GENERATED_UUID # Access user by uuid GET /users/UUID When we touch the field…
snowindy
  • 3,117
  • 9
  • 40
  • 54
3
votes
2 answers

How can I test idempotency of a method with junit?

I have to make a test the idempotency of a method. Let us say i have class Person with following method: public String doSomething(String a){ //do some stuff personDao.delete(a) } and I need to test when something goes wrong before the delete…
user1345883
  • 451
  • 1
  • 8
  • 24
3
votes
1 answer

AngularDart custom filter call() method required to be idempotent?

The main running example of the Angular Dart tutorial is a Recipe Book app. The exercise at the end of the Chapter 5 on filters and services suggests trying to "create a [custom] filter that will multiply all the amounts [of each ingredient listed]…
Patrice Chalin
  • 15,440
  • 7
  • 33
  • 44
3
votes
3 answers

How to make jQuery `bind` or `on` event handlers idempotent

Is there a way that I can call $(selector).bind('click', handler) or $(selector).on('click', handler) multiple times such that the handler only gets attached once? Right now, I have multiple AJAX handlers with different success callbacks, each of…
wrschneider
  • 17,913
  • 16
  • 96
  • 176
2
votes
1 answer

Confused about idempotency, PUT, GET, POST, etc

Most of the discussions about these topics are about how to form a URL or how to request a resource. Let me describe what I'm doing and see if the community can help me restate my problem in the more web-design-professional language :-) I'm…