Search code examples
c#architecturedomain-driven-designactorazure-service-fabric

Step wizard UI during using Microservices


I have a system that contains customer entity and user entity.

Customer is a person who pays money. Each customer contains 1-N users. Customer has links to Users.

User can not exist without customer. User entity contains CustomerId.

The problem is that I am restricted to use specific UI for creating Customers. The process of customer creating consists of 2 steps in UI:

  • Fill information about customer: firstname, lastname, address, etc.
  • Second step creates users for customer.

The main idea is to create customers and users at the end of step 2. That would be simple if I could store both of the entites at the same DB. I could do it in one ACID transaction. It would save all or nothing.

Unfortunately I use microservices - Customers and Users are different microservices with theit own storage. And both of the storages are not databases - storage has no transaction options. So Customer entity uses storage 1 and User entity uses storage 2.

I have suggested to save Customer after the first step. And then save users after the second step. But there is a cancel button at the second UI step which should delete all users and the customer which were created during whole process. Suggestion was refused. The problem is that in case user with specific username already exists, I shouldn save nor customers, nor users.

My questions are:

  • How many RootAgregates do I have? One or two?
  • Is it a correct approach to store Users in different storage than Customers storage?
  • What is a right approach in such case?

P.S. I dont like the the idea of saving users inside customers. In case of chanhging user, I need to work with customer. Another problem is that I need users to be unique in the whole system and need to get list of all users.

P.S. I user Azure Service Fabric and Actors model.


Solution

  • How many RootAgregates do I have? One or two?

    • You have one Aggregate Root and one Entity.

    Is it a correct approach to store Users in different storage than Customers storage?

    • No, it isn't. Because you should have a repository per aggregate.

    Take a look at Effective Aggregate Design by Vaughn Vernon for how to design aggregates.