Idempotency Explained: How Payment APIs Prevent Duplicate Charges

https://hackernoon.imgix.net/images/zpw3DVWOJfSJtVo0T16EOaR0BIE3-l783blh.jpeg

Idempotency: Why a Retried Payment Can't Charge Twice

Picture a user tapping Pay on a train with bad signal. The request reaches your server, the card is charged, and then the response gets lost on the way back. The app sees a timeout and does the sensible thing: it retries.

Without idempotency, that retry charges the card a second time.

The mental model

Pressing the lift button five times still calls one lift.

An operation is idempotent when doing it twice has the same effect as doing it once. The first press changes the world. Every press after that changes nothing, because the world is already in that state.

How it works

Some operations are idempotent by nature. "Set the email to a@b.com" gives the same result no matter how many times it runs. "Delete order 42" leaves order 42 gone, whether it ran once or three times.

Others are...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more

http://www.techmeme.com/img/techmeme_sq328.png

King Charles and AI leaders unveil the Dumfries House Principles for AI, a set of 10 non-binding guiding principles for responsible AI development

X: @atrupar, @lawprofblawg, @briangobosox, @sensanders, @nothoodlum, @peterbakernyt, @michaeldweiss, @carlquintanilla, @deliprao, @billkristol, @thestalwart, @jonathanvswan, @harrylitman, @katiemiller, @benjysarlin, @maggienyt, @dareasmunhoz, @bymikebaker, @atrupar, @amandalfischer, @stephennellis, @hadas_gold, @hadas_gold, @loudmouthjulia, @lanceulanoff, @patrickmcgee_, @kantrowitz, @hshaban, @ericldaugh, @jonathanvswan, @tomwarren, @senwarren, @danprimack, @alexsjacquez, @hadas_gold, @geiger_c