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
2
votes
1 answer

Why implement non idempotent operations?

In building a WEB API, sometimes we have naturally idempotent operations (like deleting a given resource) and sometimes not (like paying with a card) However, you can always use a random number as a transaction ID, to prevent it from happening more…
josinalvo
  • 1,366
  • 13
  • 26
2
votes
1 answer

Making PUT create request idempotent in REST API

My goal is to make idempotent /create REST API which is implemented as PUT verb. Idempotent RFC states: Idempotent methods are distinguished because the request can be repeated automatically if a communication failure occurs before the client is…
rok
  • 9,403
  • 17
  • 70
  • 126
2
votes
1 answer

apache airflow and idempotency of file moving

i have a workflow that i need to manage with airflow (or any other workflow engine i guess). the main issue is that the workflow needs to be started when a few files are dumped onto the file system (technically, it will be a samba mount). the first…
yee379
  • 6,498
  • 10
  • 56
  • 101
2
votes
3 answers

Apache kafka exactly once implementation not sending messages

I am trying to implement exactly-once semantic with idempotent Producer & transaction for one of the banks usecase. I have created producer like this: String topicName = "exonce"; Properties props = new…
RajashekharC
  • 164
  • 1
  • 8
2
votes
4 answers

Should a GetEnumerator method still be idempotent when the class does not implement IEnumerable

This question piggy backs of another question which I raised regarding abusing the IEnumerable interface by modifying an object as you iterate over it. The general consensus is that no anything that Implements IEnumerable should be idempotent. But…
Bronumski
  • 14,009
  • 6
  • 49
  • 77
2
votes
3 answers

Prevent compound dupes for PATH variables

I happen to be using NODE_PATH, and we have this standard thing: NODE_PATH=$NODE_PATH:~/.foo/node_modules calling this line in the bash script a few times, I get a bunch of compound duplication, such that NODE_PATH is filled with duplicate…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
2
votes
0 answers

ASP.NET WEB.API 2 sets idempotent method as POST

This method is idempotent according to the http spec which means it should be of type GET [Route("GetLoadProfile")] [ResponseType(typeof(List))] public async Task> LoadProfile(int…
Freek Nortier
  • 780
  • 1
  • 13
  • 27
2
votes
1 answer

Using aggregate version numbers to be idempotent when using event sourcing

When using DDD, CQRS and Event Sourcing, it's possible for messages to be resent or to be sent out of order. I'm not concerned with command messages so much, as the user will know immediately whether or not it was successful. What I'm concerned with…
magnus
  • 4,031
  • 7
  • 26
  • 48
2
votes
0 answers

Term for "altering passed-in variable"?

Is there a term for the style of programming where you pass in an object, add data to the object, and return the same object? Like so: public Person getAddressInfo(Person person) { Address address = lookupAddressInDB(person.getId()); …
xdhmoore
  • 8,935
  • 11
  • 47
  • 90
2
votes
1 answer

How to make this ansible jenkins script idempotent, when jenkins is rewriting its configuration?

I've a got an ansible playbook to deploy jenkins, where the jenkins config.xml jinja2 template file contains this snippet for AD authentication:
guido
  • 18,864
  • 6
  • 70
  • 95
2
votes
1 answer

Ansible linefile insertafter duplicate lines

I want to fix broken sendfile support in VBox, so I need to put line in . I want to do that with ansible playbook. Specific task look like: - name: fix broken sendfile support in VBox lineinfile: dest: /etc/apache2/sites-enabled/000-default …
Vladimir Fejsov
  • 579
  • 3
  • 7
  • 16
2
votes
0 answers

Probabilistic domain service idempotency with HyperLogLog

I'm evaluating an approach to domain service idempotency using HyperLogLog [HLL]. Aim of this approach would be to provide generic way of ensuring idempotency without storing large amounts of useless information. Only requirement being tolerance…
Grzesiek
  • 120
  • 8
2
votes
3 answers

Handling service bus Message.Complete() exceptions

Consider the scenario, an Azure service bus with message deduplication enabled, with a single topic, with a single subscription and an application that is subscribed to that queue. How can I ensure that the application receives messages from the…
MrDeveloper
  • 1,041
  • 12
  • 35
2
votes
1 answer

Spring properties and idempotentKey in uri of a File endpoint

I'm using a file endpoint to monitor changes on a file. I need to be notified whenever the file is edited (i.e., the last-modified time changes) I should specify the path of the file from properties, using Spring property placeholders Everything…
2
votes
2 answers

REST API Design - Resource relationships and Idempotency of a PUT request: What, exactly, is meant by a full resource representation?

I understand that for partial updates, an action must be taken that is not idempotent. To that end, a valid approach is to make a POST request to that resource. I have a question though about related resources. For example imagine the following…
richard
  • 12,263
  • 23
  • 95
  • 151