Lets say i have distributed architecture (client-server). On client side there is ServerEntity class, on the client side its ClientEntity class. I want ClientEntity simply to request some data from ServerEntity. I started learning DDD approach recently and actually I like domain events so I went with it. Here is my simplifed expectation of the future implementation:
- ClientEntity creates command RequestDataCommand and publishes it (e.g. through MessageBus)
- Client's ApplicationLayer gets this command, wires up it and sends to server
- Server's ApplicationLayer receives command and pushes command to MessageBus
- ServerEntity receives command and publishes domain event with some data
- Server's ApplicationLayer gets this events, wires up it and sends to the client
- Client's ApplicationLayer receives event and pushes command to DomainEventManager
- ClientEntity is subscribed for the event and when recieves it changes some internal state.
The disadvantage of the approach above is that we will end up with dozens of command classes.
On the other hand there is another option: we create some domain service interface like IRequestDataService and make it as dependency for ClientEntity. Thus we will not need to create command class and pass it to message bus, we just call appropriate method from IRequestDataService. Responces from server are recieved as domain events like in previous example.
The disadvantage of the second approach is that we use service just to send commands, which is in my vision should execute only synchronous operations.
Which approach is better and do I think the right way about client-server communication?