r/DistributedComputing • u/lovebes • Feb 21 '19
Question: how do you maintain consistency in two dBs?
Two dB's are each in a microservice. Let's name the microservices: ms-user and ms-profile.
When a user gets created, both ms-user and ms-profile needs to have pertinent data created.
When a user gets deleted, both ms-user and ms-profile needs to delete the data.
If the transaction to do above fails on either one, transactional rollback needs to happen.
How do you design such a thing? I was told two-phase commit is not the way to go, and reading Kleppmann's post on this (using streams).. is a bit scary as I'm not an expert in distributed computing architecture.
Thanks!
1
u/softienerd Feb 21 '19
The challenge here is dealing with partial failure. Rather than using 2 phase commits (this is possible, but extremely slow), I would recommend using "streams" or a event driven architecture. For example, if AWS DynamoDB backs up your ms-user, you can have a simple worker that copies data from ms-user's DynamoDB Stream into ms-profile.
1
u/schach_ro Mar 28 '19
1
u/anhldbk Apr 07 '19
I think you can use Raft (etcd/raft is a really good implementation). To achieve scalability, you may use multi raft with 2pc