web services - Handle side effects caused by duplicate POST requests -


let's have web service creates , updates meeting room bookings. updates can change various aspects of booking, such time , room number.

let's imagine user's network connection service may not reliable (e.g. mobile network), , 2 users , b try update same booking sequentially.

user sends post request change meeting time 2pm, request reaches server , server processed request successfully. however, response user gets lost due network connection, , user thinks request fails.

before user tries again, user b sends request change meeting time 2:30pm, , succeeds , responds user b successfully.

now user retries (perhaps automatically) same request again, , time both request , response succeed without problem. in other words, meeting time changed 2pm.

in hypothetical scenario above, user a's duplicated requests cause user b's request overwritten, , result incorrect state on server-side.

one possible naive solution set id each every request on client, , id not change if request re-tried/re-sent. on server-side, server maintains collection of received request ids , checks duplicates.

what better techniques or methods solving problem?

this common problem concurrent users. 1 way solve enforce conditional requests, requiring clients send if-unmodified-since header last-modified value resource attempting change. guarantees nobody else changed between last time checked , now. in case, prevent overwritten b's changes.

for instance, user wants change meeting time. sends request meeting resource , keep value of last-modified response header. then, sends post request last-modified value in if-unmodified-since header. following example, request succeeds, response lost.

if repeats request immediately, fail 412 precondition failed, since condition no longer valid.

if in meantime b same thing , changes meeting time again, when tries repeat request, without checking current last-modified value corresponding b's changes, fails 412 precondition failed.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -