Architecture Challenge with 2 databases

Viewed 35

How to handles two databases for a single rest app. I see that this is a cloud app concept but in cases that something gets deleted in DB1 and not DB2 how to handle this and make sure that both are always the same.

1 Answers

There are many ways to do this.

First you need to consider whether the DBs have the same schema and data. in such case a master-slave, master-master replication will solve it.

In the case where the schema and data is similar in some tables an not in others, in that case you can use dblink to replicate just one table Postgresql: master-slave replication of 1 table

most of the time such changes are made in the app level and if you really want to avoid dealing with 2 phase commit, you can have a queue and a service processing (retrying and recovering) the updates to both dbs

finally in the case where direct updates to the db (without passing through the app) are required to be supported, triggers and dblink is an opportunity.

Please explore these tools to get more ideas: https://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling

EDIT: start here if you're lucky enough to have the same db/data https://www.2ndquadrant.com/en/resources/postgres-bdr-2ndquadrant/

Related