Aggregate Identifier as ID for query model?

124 views
Skip to first unread message

Lukáš Vasek

unread,
Feb 1, 2016, 10:38:25 AM2/1/16
to Axon Framework Users
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

Allard Buijze

unread,
Feb 2, 2016, 4:53:16 AM2/2/16
to Axon Framework Users
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

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lukáš Vasek

unread,
Feb 2, 2016, 7:04:09 AM2/2/16
to Axon Framework Users
Hi Allard,
would you use OrderID as persistence ID (JPA @Id)?

Thanks

Allard Buijze

unread,
Feb 2, 2016, 10:06:15 AM2/2/16
to Axon Framework Users
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 ;-)

Cheers,

Allard
--

Lukáš Vasek

unread,
Sep 20, 2016, 7:20:29 AM9/20/16
to Axon Framework Users
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.

Allard Buijze

unread,
Sep 24, 2016, 1:34:38 AM9/24/16
to Axon Framework Users
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
--
Reply all
Reply to author
Forward
0 new messages