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

Idempotency in ansible playbook

I am configuring a server using Ansible playbook. My playbook works properly at the very first execution but when I run the same playbook again it creates the duplicates lines in the configuration file on the server. I am using lineinfile module.…
yogeshagr
  • 819
  • 2
  • 11
  • 20
5
votes
2 answers

SQL Idempotence

I have a post deployment script in my SQL database project, which registers default values that should be part of the database. I'd want this script to be able to be run multiple times without changing the outcome, so I can run it manually if I need…
bevacqua
  • 47,502
  • 56
  • 171
  • 285
4
votes
4 answers

Terminology for a deterministic function with no side-effects?

I need the proper terminology for a specific type of function. Suppose you write a function in your SQL database, whose inputs and outputs are contained within the scope of a database transaction. That is, if you call this function in the scope of…
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
4
votes
2 answers

Kafka topic and multiple instances of a microservice

This is more of a system design question. Let's assume I have a microservice architecture and I have X instances of Service B (to load-balance HTTP requests to the service). But, Service B is also a consumer on some Kafka topic. How can I avoid…
4
votes
0 answers

Is it possible to write a Sqitch change that drops a column, without dooming sqitch verify to forevermore fail?

This question is specific to Sqitch, but may have relevance with other database migration management tools. The first Sqitch change in my application defines its general schema: it creates all my tables tables and defines their columns. Let's say…
Jacob Ford
  • 4,553
  • 5
  • 27
  • 42
4
votes
1 answer

Message idempotence - ordering considerations

Let's say we have a system were there's one producer that queues messages in a queue and multiple instances of the same consumer processing this events. Since we are in a Competing Consumers pattern we know that ordering is no longerd guaranteed.…
4
votes
2 answers

Stream reduction identity vs. idempotent value

The java.util.stream package documentation gives this definition for identity in the context of reduction: the identity value must be an identity for the combiner function. This means that for all u, combiner.apply(identity, u) is equal to…
shmosel
  • 49,289
  • 6
  • 73
  • 138
4
votes
3 answers

HTTP PATCH is idempotent or non idempotent?

I have read lots of places that HTTP Patch is non-idempotent. Can someone explain me why it is non-idempotent ? Because as per the definition - Idempotent methods may or may not change the resource state, but repeated requests should have no…
SSR
  • 75
  • 2
  • 4
4
votes
3 answers

How can a .emacs file be made idempotent?

No matter how many times I reload my .emacs file, M-x load-file RET ~/.emacs RET I want the results to be the same as the first time. I want to make my .emacs file be idempotent. Motivation I know I can surgically evaluate a region (C-c C-r), a…
kjhughes
  • 106,133
  • 27
  • 181
  • 240
4
votes
1 answer

Python, how to deal with A(a) when type(a) is yet A

I need to create a class that mimics this behavior (in mathematics, we say list, dict, are "idempotent"): >>> list(list([3,4])) [3, 4] >>> dict({'a':1,'b':2}) {'a':1,'b':2} So, if A is my class, I want to write >>> a = A(1) >>> b = A(a) >>> b ==…
4
votes
1 answer

does post-redirect-get need to happen for an ajax request?

is there any reason to use the post-redirect-get (prg) for a request that you know will only happen via an ajax request? in this scenario, you might have a request that is sent (either via ajax or direct), and we're assuming on the back-end we can…
bharal
  • 15,461
  • 36
  • 117
  • 195
3
votes
0 answers

Probable causes for idempotent error by terraform for infra generation

We are using terraform to launch ECS containers in AWS infra using custom task definition. As we didn't require full infra to be launched every-time, a part only for launching ECS container was segregated. The launch was happening correctly, till…
khelender
  • 61
  • 6
3
votes
1 answer

How to make a MongoDB Upsert truly idempotent?

I want to insert a document into a MongoDB in an idempotent way. The explanation provided by the MongoDB documentation, and also here on SO, is to use the upsert=True modifier. However, to my understanding, this does not guarantee idempotence,…
Ulrich Schuster
  • 1,670
  • 15
  • 24
3
votes
1 answer

How to make Spring boot post api Idempotent

I have created simple CRUD api using Spring Data JPA in my Spring boot application.My Post method in the controller looks like below:- @RequestMapping(value = "/article", method = RequestMethod.POST, produces = "application/json") public Article…
Manish
  • 1,274
  • 3
  • 22
  • 59
3
votes
1 answer

clang-format makes changes to an already formatted file

When formatting the same file with the clang-format command line tool twice, changes are made both times. My understanding is that once formatted, attempting to re-format the same file should not yield any changes. Here's the test I ran: Input…