mercredi 8 décembre 2021

DDD and Microservices - data flow and structure

I'm trying to create a simple blogging platform and at the same time learn more about DDD and Microservices, so I wanted to ask you about two advises in this context:

  1. One of the business rules I assumed in my project is that only users in roles Publicist and Administrator are able to create posts, but posts created by Publicist have to be approved by Administrator first before they go public. In my understanding this is a part of a Posts.Domain, so in Post aggregate (and at the same time entity) I encapsulated changing the post's status into methods like SetPublishedStatusBy that take User (requestor) data as parameters and evaluate above rule (+ create domain events). However now I'm having some doubts whether information about requestor is really a part of the Posts.Domain. Maybe requestor should be evaulated in a different place, like Posts.API or some other service and SetPublishedStatus would be then called without parameters after it is already done?
  2. Let's stick to above context. Despite Posts microservice, I'm also developing independent Users microservice responsible for storing the users and providing some tools for Administrator to manage them. What would be then the proper data flow when a user wants to publish a new post? I'd imagine this in a following way:
  • Client sends PublishPost command with a post ID to the gateway
  • Gateway authenticates user from HTTP request (probably done via cookie with JWT)
  • Gateway sends a PublishPost command to Posts microservice
  • Posts microservice calls Users microservice to get relevant user data from DB
  • Posts microservice retreives post from DB by ID
  • All business rules are evaluated through the Posts.Domain and status is changed to Public
  • Posts microservice updates DB if everything goes fine and notifies Gateway that sends Success HTTP response

Aucun commentaire:

Enregistrer un commentaire