0

As part of an migration from .NET Framework to .NET Core we're looking to decouple elements of our monolith into more manageable modules. Ideally following a clean architecture/DDD/microservice approach dependant on each module.

Two major elements of our system include a CMS and an Ecommerce Product Catalogue.

Currently the DB schema tightly couples Product and Category to a CMS PageNode entity; in that a PageNode will have a nullable foreign key column for a CategoryId or a ProductId alongside being used for standard "content" pages. This allows the CMS to display the respective category or product page at the appropriate location in the content tree.

These concerns don't seem to belong to the PageNode itself and indeed what happens when we introduce a new module? For example a Blog. We would have to introduce foreign keys for blog post and categories?

How should we model this relationship without tightly coupling the CMS to these external modules?

1 Answer 1

2

This is a little bit hard to answer without knowing more about your CMS, but when I got this right, a `pageNode" should be able to store a list of foreign key references to all kind of "referenced things"?

If that's right, you might introduce an entity "GenericReference", with attributes

  • pageNodeID
  • ID // string
  • typeFlag // indicates if ID is ProductId, CategoryId or BlogId

The drawback is that you loose referential integrity support from the database that way - when you delete a product, category or blog entity, referencing page nodes will not automatically get updated. If that's acceptable or an issue is something you have to decide for yourself..

2
  • 1
    That's a great answer. I guess I'd use an Integration Event to signal when a module deletes an entity so that the CMS can delete the PageNodeReference entity. Loss of referential integrity might be a good trade-off for the loose coupling.
    – Andy Cox
    Commented Mar 30, 2023 at 14:44
  • Cross-microservice transactions are almost impossible to do well, so in going to microservices you tend to give up referential integrity. But you gain loose development coupling, as you say.
    – pjc50
    Commented Mar 30, 2023 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.