How to get ID in create when applying CQRS?

My take on CQRS is when followed strictly your commands don't return anything (return type void), so my example is really straight forward: How do you retrieve an ID when creating something?

For example, when creating a credit card transaction it seems rather important to return a transaction ID, or when creating a customer it would be much easier if you got the customer you created or the customer ID back so a browser could navigate automatically to that customer page for example.

One solution could be to first ask for an ID and then create the customer or transaction with that ID, but it seems pretty weird.

Does anyone have any experience with this or know how it should be done in the most effective way? Maybe I have misunderstood something?


CQRS is all about fire-and-forget, and since GUIDs are very reliable (low risk of collision) there is no problem sending in a GUID that you generate your self.

The steps would basically be:

  1. Create your command
  2. Generate and assign your identity (GUID) to it
  3. Fire the command
  4. Return the identity earlier generated

Read more about GUIDs on Wikipedia