DEV Community

Discussion on: Spring Boot 2 with Multiple DataSources

ehsaniara profile image
Jay Ehsaniara Author • Edited on

When you have a Postgres replication setup (Note: Postgres Replication is totally separate topic and I'll create a different tutorial about it since it's more related to DB Administration than Application Development). your data will be in both databases. in this scenario you are writing into the primary DB, the process is happening in the following steps:
1) Customer 1 and 2 are both written in PrimaryDB.
2) Then Postgres Replication starts, replicating the newly written data from Primary DB to the Secondary DB(s).
3) both data can be read from secondary DB(s).

Here you are using one EntityManager for WRITING and one for READING and "Data Consistency" is guaranteed by the PG replication.
The Only Issue with this method is "Data Availability", data may not be available immediately in Secondary DB(s) after it written to the primary, due to the PG replication lag.