Search code examples
domain-driven-designcqrs

readmodel for available data and selected data


I'm trying to follow DDD and CQRS principles in the project I'm currently working on. I'm now struggling with a design decision. Let's say I have a page with a list of topics a users can subscribe to. The users also sees what topics he has subscribed to. How do I retrieve the data? Do I query the topics and marked topics separately.

e.g.

  • GetTopics
  • GetMarkedTopicsForUser

and then in the view I do the magic of combining the 2 so that the users sees his subscriptions. Or do I make 1 model that contains all topics and already mark the topics the user have subscribed to

e.g.

  • GetTopicOverviewForUser

Solution

  • Let's say I have a page with a list of topics a users can subscribe to. The users also sees what topics he has subscribed to. How do I retrieve the data?

    There is various ways to do this but I would create two read models:

    • AllTopics: list of all topics
    • UserWithTopics: to see what topics a user have subscribed to.

    When constructing your page, you can then use both data to see what topics users can subscribe in that page, and probably unsubscribe. As you have at most 50 topics on both ends, performance for page construction shouldn’t be an issue.