java - Synchronizing external web request from multiple machines -


i have tricky problem webservice i'm running. i've solved in hacky way enough, i'd know if there's better do.

basically i'm running java webservice (in aws elastic beanstalk, across multiple servers). service returns results cache, if request's input not exist in cache (a sql server db), service must call external vendor. costs money, i'd ensure call not duplicated across multiple machines if happen receive request around same time (i.e. before first machine has received vendor response , written db).

currently i'm dealing issue writing "ispending = 1" row database before making external call, updating row "ispending = 0" , filling in received data once call returns. before machine issues external call, checks db pending row. if 1 found, calls .sleep() repeatedly on active thread, checking db again after each wait (30ms currently). if waits excessively, makes call (but far hasn't had happen).

so while solution works, rather complicated , doesn't solve 100% of cases. mentioned before, i'm working in aws have tools @ disposal. i'd love know if there's better way deal problem. thanks!

you use transaction isolation level of connection.transaction_serializable on transaction hold while looking value vendor. using lock database row , block selects row until commit transaction. database handle waiting you, , can handle exception case lock wait timeout sqlexception.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -