VilnaCRM-Org / user-service

Creative Commons Zero v1.0 Universal
8 stars 1 forks source link

Proposal: separate `UserRepository` and other repositories in `WriteUserRepository` and `ReadUserRepository` #41

Open paaneko opened 4 months ago

paaneko commented 4 months ago

This proposal implies dividing common repositories, that can hold save, find, get, delete methods into two - read (find, get) and write (save, delete). But write repository interfaces would be stored in the Domain layer, and read repositories in the Application layer, and their implementations as usual in the Infrastructure layer, e.g. as shown on the picture:

Screenshot 2024-07-20 at 22 18 42

And also introduce a rule that read repositories are allowed to read data from any BCs. This should solve the problem, when in the future, particular BC needs to get data from some other BCs, but without importing dependencies into the Domain layer.

P.S. I'm not a big DDD guru, but IMHO this is a good idea.

WDYT?

Kravalg commented 4 months ago

Thank you for your thoughtful proposal and for considering different ways to structure our repositories We really appreciate your input and the effort you've put into this

While the idea of separating read and write repositories has its merits, we're concerned that it might lead us to lose some of the advantages we currently enjoy with Doctrine's repository pattern and our api platform's CRUD operations If we were to implement separate repositories for reading and writing, we would need to maintain three repositories (one for read, one for write, and one to combine them) instead of one, which could increase complexity and maintenance overhead

To address the read/write concerns you mentioned, we believe a load balancer could effectively distribute SQL queries between replicas and the primary node, helping manage the load and optimize performance Alternatively, we could manage this at the application level using different entity managers or connections for different database instances, providing us with the control we need without restructuring our repository system

We highly value your contributions and encourage you to continue sharing your insights Let's keep this dialogue open and collaborative as we work towards the best solutions for our platform

paaneko commented 4 months ago

Thank you for your detailed reply! I don't think I can come up with a better solution, your described load balancer and entity managers looks like a good one)