How to ensure insertion and update of data in different databases

2

I'm developing an application with a microservices architecture and a question arose me. Each functionality of the application will have an isolated API, how can I ensure that when doing an insert / update in the functionality database x, also does an insert / update in the functionality database and? * Assuming that these features may be separate locations as well as databases.

    
asked by anonymous 17.03.2018 / 20:40

1 answer

1

It's a complicated problem to ensure a perfect solution. Look for the "Byzantine Generals Problem."

One way to solve it quite satisfactorily is to use the two-phase commit technique. In the first phase, you invoke a pre-commit API. If all services return successfully in the pre-commit phase, a second API is invoked (in each of them) by committing the commit.

There could still be a crash in the caller, so that the final commit is invoked on only a portion of the remote services, but mitigating techniques can be used (eg to note all pending operations on a journal or disk record before If the caller breaks in the middle of the list of commits, it resets the commits when it is run again.)

Anyway, the fact is that the remote APIs need to provide the basic tool, which is the commit in 2 phases. Remote services need to be thought of as, once the pre-commit has been approved, the final commmit can never fail.

    
20.03.2018 / 02:08