Recommendation concerning persistence setup in a Spring Boot / Modulith project #930
Replies: 1 comment 2 replies
-
Hi @KUnger-Spg, I've asked myself the same question and like you, I'd be very interested to hear from others what approach they take. I'm happy to share my current view but I'm no expert and I'm hoping others say more. One comment on your statement that:
All the official examples that I've checked (e.g. the RESTBucks app) use a single db schema and allow inter-model references between modules. For example, in the RESTBucks application, the However, as you suggest, there may be some motivation to use concepts from DDD to ensure e.g. that foreign aggregates are referenced only by id. The RESTBucks application uses For myself, the conclusion I've reached (pending input from others with more expertise) is that it depends on why one is using Spring Modulith. If you simply want to organise your code by feature module, take some easy steps to reduce coupling between modules, and take advantage of nice Spring Modulith features like limiting inter-module connection points and using ApplicationEvents, then it's fine to use a single DB schema and have inter-module model dependencies. But if you want to separate modules out which might potentially become their own microservice, then it may be worth going for a greater level of decoupling, which would involve having no inter-module model dependencies, no inter-module foreign keys in the database, and allowing only async communication between modules via Events or synchronous communication by a module's public service API. By removing inter-module model relationships and their underlying foreign key constraints, you'd be a big step closer to extracting those modules into a separate microservice. And you could do this either within the same database schema or by using a schema-per-module pattern. However, be aware that having separate databases makes it more difficult to achieve cross-module queries or transactions. |
Beta Was this translation helpful? Give feedback.
-
I'd like to ask the community about your experiences and preferences whether you provide
for your Spring Boot / Modulith application!
As we do not want references to entities of another aggregates/modules (no fk-references, no
@ManyToOne
),how do you ensure these constraints.
Do you use ArchUnit test rules or do you also have those rules also expressed in the DB (different users for different schemata, different DBs)?
Looking forward for your feedback!
Beta Was this translation helpful? Give feedback.
All reactions