Skip to content

Latest commit

 

History

History

boot-read-replica-postgresql

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

boot-read-replica-with

This project is an example to show how we can separate read and write operations to primary and replica databases using spring boot and postgresql database.

A read replica in Postgres is a database instance that receives data from a primary database instance and serves it to clients. Read replicas are useful for scaling database workloads, as they can offload read operations from the primary instance, allowing it to focus on more resource-intensive tasks such as writing data. This can improve the performance of the overall database system. Read replicas can also be useful for providing high availability, as they can take over read operations if the primary instance becomes unavailable for any reason.

  • All reads will go to reader instance and writes will go to writer instance
  • Switching between master and replica can be observed in docker compose logs or application logs when datasourceproxy is enabled.

Architecture Image Credit : Vlad

Liquibase

Use below script for generating the difference in the database

./diff.sh

Run tests

./mvnw clean verify

Run locally

docker-compose -f docker/docker-compose.yml up -d
./mvnw spring-boot:run -Dspring-boot.run.profiles=local

Useful Links

Reference