DDD: Using External Websocket

Viewed 256

I am trying to design a microservice using DDD approach. Microservice has an aggregate whose state/logic depends on the data received over WS connection to a thrid-party server. WS is used because of latency issues.

According to my understanding, DDD seems to indicate that external APIs have to go through application layer. Except WS connection instantiation, there will be lot of to and fro for dataflow with this approach in application layer. Not sure how to go about this.

1 Answers

A web-socket is a form of connection between your microservice and another component. There are other forms of connections as well, e.g. request/response and message queues. Connectivity is an infrastructural matter, therefore its implementation (instantiation or receiving data) should reside not in the application layer but in an infrastructural layer.

Once data is received through web-socket channel, it should be packed into an application service.

According to my understanding, DDD seems to indicate that external APIs have to go through application layer

External API invocations, much like web-sockets, should be implemented in an infrastructural layer. If an API is used to retrieve data, it should probably be abstracted away as a repository (in line with DDD principles: repository interface in domain layer, concrete repository invoking API in infrastructure layer). And application service calls repository interface.

Related