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
Use below script for generating the difference in the database
./diff.sh
./mvnw clean verify
docker-compose -f docker/docker-compose.yml up -d
./mvnw spring-boot:run -Dspring-boot.run.profiles=local
- Swagger UI: http://localhost:8080/swagger-ui.html
- Actuator Endpoint: http://localhost:8080/actuator
- PgAdmin : http://localhost:5050([email protected]/admin)