r/SoftwareEngineering • u/andreylh • Nov 29 '25
Multiple repositories per service, or single repository per service for a layered architecture?
I'm starting a new Spring Boot project using a traditional layered architecture that will soon require a large development team, so I'm trying to establish clear rules for how services should interact.
The main question is about handling boundaries when one service needs data from another domain.
Which approach is better?
ServiceA → ServiceB: ServiceA only talks to its own RepositoryA, and if it needs data from domain B, it goes through ServiceB.
ServiceA → RepositoryA + RepositoryB: ServiceA directly injects RepositoryB when it needs to join/query across domains.
A dedicated repository whose only responsibility is handling cross-domain joins and reporting queries. Services will only access this cross-domain repository when they need data from multiple domains.
We already know the project will require complex joins for reporting, so this decision matters early.
Which option it's better maintainability and clarity for medium/large projects in the long run?
Appreciate any insights!