Skip to content

Implementation of CQRS with read only queries directed to the Postgres replica via seperate database context

License

Notifications You must be signed in to change notification settings

ArturMarekNowak/CQRS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CQRS

Build Trivy and dockler CodeFactor

This project is a PoC of queries distribution between replicas of postgres databases

Table of contents

General info

The idea was to split databse contexts into three:

  1. Base - base database contexts from which remaining contexts are inheriting DbSet<T> properties from
  2. 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
  3. ReadOnly - the context that that can run only SELECTs. This database context is utilized by CQRS handlers which take CQRS queries as input

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

Technologies

  • .NET 8
  • Postgres
  • Docker

Setup

  1. Run docker compose in src folder: docker-compose up
  2. API should be accessible from http://localhost:8080/swagger/index.html

Status

Project is: finished

Inspiration

Performance problems

About

Implementation of CQRS with read only queries directed to the Postgres replica via seperate database context

Topics

Resources

License

Stars

Watchers

Forks

Packages