3

Description:

Given an aggregator portal the user must be able to create, read and update the requested entity. The entity here are all of different types and live in different systems. The portal shows the metric of the entities at a given unit of time and allows an user to filter the details by their type, name etc. The system is basically ticketing based system where the user must first create a ticket for each request (i.e. create, modify and delete).

The user may have different roles eg: user, admin and team lead etc. The user can create, modify and delete (only before cancellation and resolved phase).

Example:

Given there are four different kinds of entities Bag, Car, Oven and Apple. They all have their own external system, my system should allow the user to create these resources (which ultimately delegates requests to the original system), filter them based on their type, modify and delete them. The system should be responsible for keeping track of each requests.

                         Resolved
                        /
                       /
   New --- Waiting ---
                       \
                        \
                         Cancelled

Problem:

At present all the external systems have their own notion of unique ID and sometimes not for example an apple has a name Foo in box A but another box B may have an apple with same name.

Second, the Apple system may decide to shift Apple Foo to some other box Z, how could I know that the apple Foo in box Z is same apple?

So, basically I am struggling to define unique ID for each resource in my system which could be linked with entities in external systems.

Hope the question is clear because I have tried to trim the description and question as they are part of more complex domain.

PS: I am new to domain driven design so please point me to proper references while using key terms.

  • What is wrong with creating your own unique ID and then saving pairs of your ID with ID of other system? – Euphoric Sep 9 '17 at 8:41
  • @Euphoric an example please? – CodeYogi Sep 9 '17 at 9:01
  • @CandiedOrange updated the description replaced with box. – CodeYogi Sep 9 '17 at 15:30
  • @CandiedOrange basically what I was referring in the box analogy was that the remote entity can be moved, updated etc so, how could keep track of those changes? for example a database is identified with its unique name in a VM but it may be moved to a different VM, in my system I had VM name and DB name as a unique identifier. – CodeYogi Sep 9 '17 at 15:32
2

Assumptions

To summarize, your system deals with entities that should be created and owned by other systems and you need to track their identity across the system landscape.

It is not clear to me if your system operates within a single larger domain, or if your system copes with a its own consistent subdomain, that is relatively independent of the others (ticketing). I'll assume the latter, so we'll reason within your bounded context.

Own id, or not own id ? That is the question

In your bounded context, you should identify the entities that your ticketing system has to manage:

ENTITY: An object fundamentally defined not by its attributes, but by a thread of continuity and identity. -- Eric Evans in Domain Driven Design

Your question suggests that there is no single authoritative reference system that could uniquely define the ID of an entity across the landscape. So it seems reasonable to manage your own unique ID to track the identity of your objects.

Managing the link

Any of your local entity is related to one or several foreign entities managed within the other systems. These foreign entities (defined by a foreign system id and a foreign entity id) have in your bounded context no meaning without being associated to your own local entity that acts as glue. So the foreign entities should belong to an aggregate to which your local entity would be the aggregate root:

AGGREGATE: A cluster of associated objects that are treated as a unit for the purpose of data changes. External references are restricted to one member of the AGGREGATE, designated as the root. A set of consistency rules applies within the AGGREGATE’S boundaries.
-- Eric Evans in Domain Driven Design

Mapping the objects

Now the difficult part will be the mapping of your object: how to identify the identity of objects across the landscape? When is Foo in Z the same apple than Foo in A ? When is Foo in B a different apple than Foo in A, When is Foo in A the same as 123 in C ?

Four options:

  • either you have some set of characteristics that uniquely identify a same object: for example Martin Smith born on 1/2/63 in Paris can be identified based on these 4 informations with a very high probability across different system, even if they use different ids such as national security number, passport number, customer number, or employee number. In this case, you can with appropriate queries build your mapping whenever you need it,
  • or you have at least common subsets of entity data that can help to match the same identity of two entities in two systems at a specific moment in time.
  • or the other systems must contribute to the mapping building. This could for example be achieved through an event driven architecture, in which the systems that create or transfer entities would send messages that would be consumed by your system to keep in sync.
  • or a mix of the above

All this assumes of course that the entities are objects that really have an identity, and not "anonymous" value objects, whose identify doesn't really matter.

Mapping bounding context

Finally, and from a domain modeling perspective, it would be sound to maintain a context map, that maps your domain model of your bounded context, to the domain model of other bounded contexts.

  • I don't know anything about context map, can you please guide me to some proper reference? – CodeYogi Sep 9 '17 at 12:13
  • @CodeYogi This article should tell you more about context and maps: infoq.com/articles/ddd-contextmapping - I also would recommend Evans' book that I quoted above. A little expensive but definitively worth its price – Christophe Sep 9 '17 at 13:18
0

At present all the external systems have their own notion of unique ID and sometimes not for example an apple has a name Foo in box A but another box B may have an apple with same name.

If this was all you were dealing with it'd be easy. Just concatenate the box ID with the entity ID and you'd know that:

A::Foo != B::Foo

Second, the Apple system may decide to shift Apple Foo to some other box Z, how could I know that the apple Foo in box Z is same apple?

This is what makes it hard. Because now:

A::Foo == Z::Foo

So, basically I am struggling to define unique ID for each resource in my system which could be linked with entities in external systems.

You can either mine your apple for unique identifiers or you can use the fact that you're allowed to modify the apple and tell the apple to:

enter image description here

  • There is a weekly script which runs to update all the apple details on my system by using web services of the external systems hence its important to which things have moved, by the way nice picture :) – CodeYogi Sep 10 '17 at 7:19
  • "important to which things have moved" I assuming your talking about what you called "second" before. So long as you've given the apple your number checking if any other apples are the same apple should be easy regardless of system or how often your script runs so long as the same apple doesn't exist in two places without your number. – candied_orange Sep 10 '17 at 15:16
  • What you are saying is generating my own ID and save this ID in the external system with their Apple's details, right? – CodeYogi Sep 10 '17 at 16:35
  • I'm saying if you can't or don't need to mine an identity from these entities when you first encounter them you could at least tag and release them to give them one that means something to you even if they mean nothing to anything else. – candied_orange Sep 10 '17 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.