Search code examples
microservicesdomain-driven-design

DDD - Save data from another microservice


I work in a company that owns multiple other companies (each have it's own apps), and we are starting to centralize some data, for example, now we have a service that will share customer data for every company, let's name it CustomerService.

The project i'm working uses a subscription model , where the customer can subscribe to a health insurance plan and can have only one active plan (let's call it HealthInsuranceService).

We have to show which plan the customer is subscribed in some apps from our ecosystems, for example, we have a drugstore app and we have to show which plan this customer has in the customer profile in the drugstore app. In terms of DDD which option is better?

  1. Save the planId in CustomerService, so every app can have access to our planId. I see some drawbacks here, for example, if we allow every service to store its data into CustomerService it will grow with data that will be used only for some apps. And a get Customer endpoint will get bigger and bigger.
  2. Save the planId and cache some customer data in HealthInsurance, using event-driven. Every app that needs this info will have to call an endpoint from this service to retrieve the planId. The drawback here is that it will be another request to get the planId.
  3. Cache planId (through event-driven) in the drugstore app and in every app that needs this data.
  4. Use api gateway that will be used for all apps to merge customer data from customerService and plan data from HealthInsuranceService.

Do we have any better option?


Solution

  • None of those strikes me as intrinsically any worse than the others from a strictly DDD perspective. Which one to choose depends on what's important to the problem.

    Option 3 is probably what I'd tend to go for (which is basically CQRS) is what I'd tend to go for in order to ensure service autonomy, but that autonomy entails looser consistency guarantees (i.e. a change to the insurance plan might not show up immediately in the drugstore app). If a stronger consistency guarantee is warranted, on the other hand, option 3 is almost certainly the worst of the 4 options.