Steven Brookes
Steven Brookes

Reputation: 894

retrieving data in CQRS Command side from another bounded-context

I am trying to implement CQRS for the first time, and have an issue where I am receiving data from an external system which has a field which is a string reference, for example, username. I need to get the ID that the reference relates to, and reject if that ID isn't found.

The ID is from a separate bounded-context, and would seem inefficient to load the entire record to just get the ID. I was wondering if there was a CQRS pattern compliant way of returning just an ID based on a name/reference from the Command side, as it would seem like more of a Query concern (but maybe I'm being a bit naive?)

Upvotes: 3

Views: 1309

Answers (1)

Kanishk
Kanishk

Reputation: 431

I don't think there would be any query concern in this. The Query Side in CQRS is primarily for the read clients but that doesn't mean you cannot query at all internally on the command side. It's absolutely OK to receive a request, query some data (like events from event store/ message queue or any other kind of data) and take some action (like raising an event or not) based on that data. In fact, the whole idea of Event Sourcing relies on querying the old events and rehydrating the current state of an aggregate.

Another approach instead of querying could be that you can subscribe to the events raised by the other bounded-context and particularly subscribe to the event which contains ID of the reference and maintain a list of all the ID-username pairs in the first service.

Upvotes: 1

Related Questions