I would like to make sure fields in two independent third party databases hosted in different places are sync. I have the following generic node / express js code:
router.post ('url', function(req,res,next) {
third_party_api_1.set_a (req.body.param, function(err, a) {
third_party_api_2.set_b (req.body.param, function(err, b) {
res.end()
})
})
})
If an end user post (param = 1) I expect (a = b = 1). If they post (param = 2) I expect (a = b = 2). If two users post (param = 1) and (param = 2) at the same time, will a and b in the third party databases always be equal? I understand that they can be 1 or 2 depending on timing, but I want to make sure it is either (a = b = 1) or (a = b = 2) but not (a = 1, b = 2) or (a = 2, b = 1).
In other words, will set_a
and set_b
be "atomic"?
Thanks!
EDIT #1: "a" is a single value in a third party database, "b" is another single value in another third party database, I would like to have the user post a single value and my code replaces both a and b to that user value.
EDIT #2: I have no direct control over the third party databases, I can only call a public api. Perhaps I need a mutex around the api calls? How can I implement that?
You seem to be asking about “consistency” between two distributed systems not atomicity.
What you are asking is really more an architectural question rather than anything particular to JavaScript. If you are making calls against two different data stores, you would need some means to ensure these two endpoints are keep consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With