Entity global/local IDs and Refactoring in Domain Driven Design

198 views
Skip to first unread message

Michael Ainsworth

unread,
Jan 11, 2016, 6:15:23 PM1/11/16
to DDD/CQRS
In Eric Evans' book, he says root entities (aggregate roots) have global identity. Entities inside the boundary have local identity, unique only within the aggregate.

What happens when you discover, like the team in Vaugn Vernon's "Effective Aggregate Design" (http://dddcommunity.org/library/vernon_2011/), that you need to refactor one aggregate root into several? If you're already in product at this point, how do you enforce global identity for the previously locally identified aggregates?

Greg Young

unread,
Jan 11, 2016, 6:19:39 PM1/11/16
to ddd...@googlegroups.com
because local + global = new global
> --
> You received this message because you are subscribed to the Google Groups
> "DDD/CQRS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dddcqrs+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Studying for the Turing test

Danil Suits

unread,
Jan 11, 2016, 6:58:03 PM1/11/16
to DDD/CQRS
Next on "Guesses from a Novice"...

I understand this to mean: the internal entities already have a globally unique identity.  Which is to say, they are uniquely addressable via the tuple (aggregateId, localEntityId).

In some circumstances, you are done: the unique identifier for the entity as new aggregate is the same as when it was enclosed; you are just looking it up a different way.

If you are using something like a uuid for all of your identities, that doesn't work.  However, there are deterministic recipes for creating a named uuid from sources.  Since the tuple is unique, createNamedUuidFrom(tuple) is also going to be unique [1].

[1] Not an absolute, but to many nines.

After that, I'm not sure what the right play is for cleaning up the history.  I'm almost certain you want to append new events to the existing history to make that happen, but I don't yet see the right strategy for doing that.

Michael Ainsworth

unread,
Jan 11, 2016, 7:03:26 PM1/11/16
to DDD/CQRS
Well that seems easy enough! If using UUIDs, it's probably a good idea to use a named UUID generator in producing the new global IDs.

Thank you for your feedback.

@yreynhout

unread,
Jan 12, 2016, 3:19:42 AM1/12/16
to DDD/CQRS
I often use a guid for entities from the get go - makes these things easier to cope with.
Reply all
Reply to author
Forward
0 new messages