read-replica-with-spring-boot
Last updated
Last updated
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
Swagger UI: http://localhost:8080/swagger-ui.html
Actuator Endpoint: http://localhost:8080/actuator
PgAdmin : http://localhost:5050(pgadmin4@pgadmin.org/admin)
https://stackoverflow.com/questions/25911359/how-to-split-read-only-and-read-write-transactions-with-jpa-and-hibernate/26026237#26026237