Good day, dear!
There are several applications, each of which accesses a web service, collects data from it and processes it. It is necessary to apply periodically (the data changes with the passage of the day, imagine that this is the exchange rate from the Central Bank website). Question: how to synchronize applications so that they do not save the necessary data twice? Allow access to the service only one application can not.
If there was only one client, I would do this: I would take the data, save it to the database and the database cache, check whether there is any such data at the next call.
But the situation is more complicated. You can save data in a shared database, but since there is no synchronization, there is no guarantee that clients will not start at the same time and simultaneously bring the same course value into the database (for 15:00, for example). What are my options?
Somehow to lock a DB while one of clients is fulfilled. Like
lock
orsynchronized
in Java. It can be done?Load all into one table with a query like
insert if unique
, and then read from there. In principle, the normal option, although it seems to me more resource-intensive than the first.Save the index of the next client in the table so that the rest will not start at the same time (that is, spread them out in time).
What do you think?