Aggregate Identifier as ID for query model?

Hello,
I’m thinking about IDs “mapping” between command and query models.
What is the best practise to do so? Is it ok to put aggregate identifier as “persistence id” for query model? Or is it better to separate them and use custom fields for id and aggregate identifier?

Thanks

Hi,

why a mapping? If you ave an OrderID for the Order aggregate in the command model, why not use that same OrderID in the query models?

Cheers,

Allard

Hi Allard,
would you use OrderID as persistence ID (JPA @Id)?

Thanks

Yes, unless there are certain functional requirements to that ID (e.g. sequential numbering). In that case, I’d distinguish between a functional ID and a technical one. The technical being the @Id.

Note that for scalability, a client generated random ID (e.g. UUID) is the best option. Client = server-side sender of command, not ui :wink:

Cheers,

Allard

Hi Allard,
If you need to create technical id based on sequence do you know that id before command execution?
If so how are you generating it? Do you have some shared service which generates “sequences”?
If no, I guess you are joining data in query model with functional id (UUID), but when you have a lot of data, this could be very slow.

Hi,

in some cases, I add an autoincrement column in the database as primary key, and the OrderId (UUID) as a unique sec key. That’s just a performance improvement. The autoinc isn’t used anywhere.

If the sequence number is functional, I use a service to generate these values when aggregates are created.

Cheers,

Allard