Check out the readme
a. Leader-based replication
b. Leaderless replication -- Dynamo-style. checkout dcache
-
Synchronous Replication The flow includes
- send a
POSTrequest to master on endpointsync-usersensure that write happens - Next, send it to all followers within the same response before responding to the client
- Prometheus metrics are registered to track important information
- send a
-
Asynchronous Replication The asynchronous flow is
- send a
POSTrequest to master on endpointasync-usersensure that write happens, then respond to a client immediately - watch how replication is carried out in postgres. Necessary configuration is here
- send a
There are several ways of handling read-replicas
- Application Layer, this is where you manually route the db requests to the appropriate replica in the application logic. This issue with this is that its application routing logic can be complex and error-prone.
- Database Layer, this is where you configure the database to route read requests to the appropriate replica. You can use tools like pgpool-II, pgBouncer or Vitess to achieve this. The issue with this is that it can be complex to set up and maintain, and it may not be suitable for all use cases.
Something I saw online, just dumping it here.
--- Verifying replication lag
SELECT
application_name,
client_addr,
state,
sent_lsn,
write_lsn,
flush_lsn,
replay_lsn,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)) AS replication_lag
FROM
pg_stat_replication;