0

Suppose I have in my domain model two aggregates: Dog and Cat. Dog is composed of DogName and DogFood. Cat is composed of CatName and CatFood.

The repositories, however, are a PetNames API which only provides a single endpoint to retrieve all names, and PetFoods API which only provides a single endpoint to retrieve all foods. They are both 3rd party. I have no control over them.

There are times in my Use Cases where I need to rehydrate both a Dog and a Cat for some operation. The calls to the two repositories are expensive and I don't want to make multiple calls that retrieve identical data for each aggregate.

How do I go about rehydrating the aggregates in this case?

3
  • Unless something can be both DogFood and CatFood at the same time in your domain model, the two calls to the PetFoods API should be retrieving different items, which means that any similarity between the retrieved values is coincidence. You are, by definition, not retrieving identical data. Feb 26, 2020 at 15:23
  • @BartvanIngenSchenau There is just a single endpoint that returns a collection of all PetFoods.
    – asciiman
    Feb 26, 2020 at 16:56
  • PetFoods returns you the list of all foods for all types of pets? No filter possible?
    – rogerdpack
    Feb 27, 2020 at 17:10

1 Answer 1

1

I would recommend that you simply cache the response from each API endpoint in memory so that, after the first call, any subsequent calls use the cached data (and therefore don't have to hit the API again).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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