I need to build an application to be installed in a local host to be used for local clients even if there is no internet, but also need to guarantee that remote clients can continue using the application although the local server has no internet.
I thought about having two instances of the application one working in a local server and one in the cloud. While the local server has internet all queries go to it and the primary database is stream replicated on the cloud.
When internet cuts off remote client can continue using the app to query it and with only one write opperation allowed. Local instance can continue working without any problem.
When internet connection is restored to the local server both databases should sync and restart strem replication between the two servers.
I found that using postgres stream replication does not support that the old primary db continue add information. For example with pg_rewind all new information in the old primary is remove before sync up with old standby db.
I need a way in wich I can use both databases independiently for a while but then sync both in a primary DB. How could I do it?
Below there is some schemas to make it a bit clear.
schemas