Search code examples
domain-driven-designcqrs

Is it okay if the command model(microservice) knows the resource url of the query model in 201 created response? (CQRS)


I divided my application into the command model and query model.

When the command is executed on the command model, the event is published, and then the query model creates its own data and persists. (it occurs in the same transaction.)

When the user sends data with Post method, the command model has to return created 201. My question is that is it okay the command model knows about the query model's resource URL? (is it okay for the command model's controller to be coupled with the query model?)

For example)

Request

Post /articles

body: { title: "the title", body: "the body"}

Response

201 Created

Location: /subscription/news

the UI only reads data from the query model and the query model has some different URL patterns compared to the command model, and they only provide news as a collection.

Is the above example make sense? What do you think?


Solution

  • Putting a reference to the query service's (GET) request in the HTTP response of the command service's (POST) reponse does not imply both services are coupled. Only information about where to find the freshly created resource is stored in the header but the services and their functionality remain separated.

    If you want to know more about automatically creating the URL's (I assume you mean hard coded URL by coupling between services) instead of hardcoding them, you could also take a look at HATEOAS...