Optimistic Blocking and HTTP If-Match Header

What are your experiences in using If-Matchto implement an optimistic blocking scheme in a web service?

To simplify the situation, let's say we build a simple CMS consisting solely of "pages", each of which has only a body. If two users start editing the same page at the same time, only the changes made by the user that were the last to be saved are recorded (or, rather, they overwrite those made by another user.)

To prevent this, I plan to use conditional PUTs, i.e. Retrieve the response header value ETagand supply it as the header value If-Matchin the request PUT. If this value does not correspond to that based on the current state of the page, the server rejects PUTwith 412.

I am aware of an obvious trap in which race conditions may arise between checking a precondition and actually updating the database, but they can be eliminated by transactions and sorting.

Have you tried this in practice? It is a bad idea?

+3
source share
1 answer

, , "-", , , .

+1

Source: https://habr.com/ru/post/1736106/


All Articles