Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Models required across multiple domains #30

Open
RTS340 opened this issue Sep 23, 2020 · 1 comment
Open

[QUESTION] Models required across multiple domains #30

RTS340 opened this issue Sep 23, 2020 · 1 comment

Comments

@RTS340
Copy link

RTS340 commented Sep 23, 2020

From looking at your guide I am struggling to find a good approach on how to use interfaces to use cross domain models.

If we take a Book and Author example, where these are separate domains. If we have an api endpoint that lists all the books in the system and as part of the data we want to return the authors name. How would we do this without having to make a request to the Author interface for each book that exists to get its details. As this could cause alot of requests to the database i.e. 1 query for the list of books + x number of queries for each books author.

This problem would become more prominent if the different domains live on separate hosts.

What is the approach you take? I have seen you have mentioned having a UserSerializer in the domain for its context (which makes sense), but how would you pass your data between the two domains?

Thanks

#12

@RTS340 RTS340 changed the title [FEEDBACK] Models required across multiple domains Sep 23, 2020
@phalt
Copy link
Owner

phalt commented Oct 14, 2020

Hello!
This is a good question, and I've dealt with a similar issue like this before, where we wanted some information usually stored in Domain B, but we wanted it regularly in Domain A.

Keep in mind that the Books/Authors example is probably a bad one for this case, because for a Human's perspective it makes sense to keep those models together.

Remember that a Domain should store information that is relevant to it, ideally within it's own Domain. Definitely if it is information you need a lot, such as the Author's name. So in your example I would see keep a copy of the Author's name in the models in the Book's Domain. This is duplicate information yes, and you'd need to keep the two Domains in sync, which is no different from the usual strategy we'd take if we had two distinct domains that needed to keep a shadow model in sync.

See this bounded context example where they are duplicating information at the boundaries of two domains, because it is cheaper to keep them in sync than to make more expensive cross-domain queries often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants