This project is a PoC of queries distribution between replicas of postgres databases
The idea was to split databse contexts into three:
- Base - base database contexts from which remaining contexts are inheriting
DbSet<T>
properties from - ReadWrite - the context that that can run SELECTs, UPDATEs, INSERTs and DELETEs. This database context is utilized by CQRS handlers which take CQRS commands as input
- ReadOnly - the context that that can run only SELECTs. This database context is utilized by CQRS handlers which take CQRS queries as input. This class overrides
SaveChanges
andSaveChangesAsync
methods and throws an error in case they are invoked
On the database level seperation is done by creation of replica and usage od dedicated connection string. Replica accepts only read only queries where as primary database accepts all queries. ReadOnly context utilizes connection string with ro_user
database user where as ReadWrite context utilizes connection string with rw_user
.
Pic.1 Visualization of the project
Overall project are three docker containers. One with .NET API and two with postgres databases - one primary database and one replica.
Pic.2 Visualization of docker compose project
- .NET 8
- Postgres
- Docker
- Run docker compose in src folder:
docker-compose up
- API should be accessible from http://localhost:8080/swagger/index.html
Project is: finished
Performance problems