Search code examples
microservicesdomain-driven-design

DDD data duplication for microservices


I have User, Payment, Product, Checkout services. User means for payment; payer , Product; seller, Checkout: buyer etc. When new user registered. I publish event which contains user. And Store user data for all services. That means 15000 user is X4 = 60.000 user data for all services.

Is that Ok ?

Or what should I do ?


Solution

  • Is that Ok ?

    The duplication of required data itself is totally okay from my point-of-view in a Microservices architecture if it happens for the right reasons. And I even would not necessarily consider this as a normal data duplication in the first place.

    Each Microservice has it's own domain model and thus the User model - which you already name differently in the different services (payer, seller, etc.) - represents something different in the different contexts. There is very likely also data added to those user objects in each service that are not even known to the user service.

    Or what should I do ?

    ... but you should still reflect on the representation of the user data in each of your services. It might not even be necessary to build a projection of the user model (seller, buyer, etc.) in each of your services as soon as the user was created.

    I would only do that if I needed to have some user information at hand already inside, for instance, the product service when I have to perform some domain logic. There is a good chance you only require the id (or let's say unique username) of the corresponding user in one of your services to connect a user to some domain entity. Or you could even create the corresponding user object on demand, e.g. during a checkout process.