Re:Idempotence: What is it and why should I care?
by rectangletangle on Monday August 20, 2018 @10:01PM
(#17806233)
This is solid advice. Another common trick is to disable the submit event when the submit button is clicked for the first time, preventing two requests from firing, when the user double clicks. Then re-enable the event, if the request fails. Ideally this is done in addition to server side nonce validation, and not as the only preventative measure, because browser differences, or network issues could cause a double request (more likely if the HTTP GET method is used, instead of a proper POST). Regardless server and client side techniques should be used together to create a better UX, similar to using both client and server side email format validation.
[ Parent
| on HN ]
Re:Idempotence: What is it and why should I care?
by digitaLandscape on Monday August 20, 2018 @10:37PM
(#17806432)
I don't like this because in practice sites usually fail to re-enable the submit button if something goes wrong. Just let the user submit multiple requests if they want to retry, don't take that away from them, just make it harmless.
Re:Idempotence: What is it and why should I care?
by jen729w on Tuesday August 21, 2018 @05:31AM
(#17808233)
Newbie programmer here, but even I am already implementing finite state machines which handily fix this sort of issue.
Any sort of UI without them now feels archaic.
Re:Idempotence: What is it and why should I care?
by hood_syntax on Tuesday August 21, 2018 @08:52AM
(#17809082)
Agree 100%. If you don't have explicit state transitions in a UI, you're asking for trouble. I think some people don't realize how much harder they make it on themselves by not setting clear boundaries; they see the up front cost and balk, when it saves a non-trivial amount of headache in the future, not to mention reducing mental overhead when you've got the structure hashed out.
Re:Idempotence: What is it and why should I care?
by digitaLandscape on Tuesday August 21, 2018 @11:13AM
(#17810301)
Meh. The logic still applies: on a bad network, the first request can hang for half a minute when a retry would get lucky and go through immediately.
Don't handcuff your users for no benefit, just because you can't write a well-behaved backend.
Re:Idempotence: What is it and why should I care?
by PinkMilkshake on Monday August 20, 2018 @10:29PM
(#17806384)
That's only a partial solution. It may be a user agent or a queuing system (or anything else sitting between a person clicking the button and where the final transaction is recorded) that attempts a retry.
Re:Idempotence: What is it and why should I care?
by BoiledCabbage on Tuesday August 21, 2018 @01:42AM
(#17807289)
Restricting what the client can do isn't idempotency. Allowing the user to perform the same action (make the same api-call) multiple times, Nd your API coalesce them as if it were 1, is. The point and benefit of idempotency on this scenario is that you silently support "bad" behavior.
Re:Idempotence: What is it and why should I care?
by qoi2ijds0 on Tuesday August 21, 2018 @07:48AM
(#17808754)
IMO disabling buttons causes more trouble than it's worth - you can never guarantee the user hasn't clicked twice (because don't forget the code that disabling the button in the first place is relying on an event firing that tells you the button was clicked - this doesn't mean 2 events can't be queued before the event handler is called), and then you need a whole chunk of code around re-enabling the button depending on what has happened after the fact which is then a big source of bugs.