Journal of Distributed Software Engineering, Architecture and Design
Domain Model != Data Model
<div class="cs-rating pd-rating" id="pd_rating_holder_1819065_post_2195"></div>
<p class="wp-block-paragraph">One of the smells when practicing DDD (Domain Driven Design) is when you are presented with a Data Model (extracted from an existing set of tables or constructed through rigorous but confirmed hypotheses) and asked to consider this as your Domain Model</p>
<figure data-carousel-extra='{"blog_id":1,"permalink":"https://alok-mishra.com/2021/11/26/domain-model-data-model/"}' class="wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-large"><a href="https://alok-mishra.com/wp-content/uploads/2021/11/domain-aggregates-techiecook-1.png"><img data-id="2204" src="https://alok-mishra.com/wp-content/uploads/2021/11/domain-aggregates-techiecook-1.png?w=1024" alt="" class="wp-image-2204" /></a></figure>
<figure class="wp-block-image size-large"><a href="https://alok-mishra.com/wp-content/uploads/2021/11/data-model-techiecook-2.png"><img data-id="2205" src="https://alok-mishra.com/wp-content/uploads/2021/11/data-model-techiecook-2.png?w=1024" alt="" class="wp-image-2205" /></a></figure>
</figure>
<p class="has-text-align-center wp-block-paragraph">Domain Model is not the same as a Data Model</p>
<p class="wp-block-paragraph">This is an easy trap to fall into because both contain describe some information model and capture references. Yet, there are key differences and there are 2 key things that I would consider </p>
<h2 class="wp-block-heading" id="1-business-led-or-technology-led-model">1. Business led or Technology led model?</h2>
<p class="wp-block-paragraph">Ask <strong>who</strong> created the model? </p>
<p class="wp-block-paragraph">A <strong>Domain Model</strong> is created in conversation with <strong>Business and Technical Domain experts</strong>. The <strong><em>key to this model is</em></strong> <strong><em>language</em></strong> – we capture nuances of language and the context. These help us understand there are subtle variations of the information model in different contexts</p>
<p class="wp-block-paragraph">For example, if I describe the word “Cart” then you are curious as a domain modeller to ask me the context (Shopping-Cart, Gardening-Cart or Mario-Cart depending on Shopping, Gardening or Gaming contexts)</p>
<figure data-carousel-extra='{"blog_id":1,"permalink":"https://alok-mishra.com/2021/11/26/domain-model-data-model/"}' class="wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-large"><a href="https://alok-mishra.com/wp-content/uploads/2021/11/domain-story-techiecook.png"><img data-id="2207" src="https://alok-mishra.com/wp-content/uploads/2021/11/domain-story-techiecook.png?w=1024" alt="" class="wp-image-2207" /></a><figcaption>A domain story from business experts</figcaption></figure>
</figure>
<p class="wp-block-paragraph"> In contrast a Data Model comes from <strong>technical</strong> point of view and may not capture behaviour and nuances in language. The risks are that the technical model may have generalised language leading to multiple contexts accessing the same model leading to coupling across these context which we want to avoid. We must evaluate the data model presented in the context of an organisation against the various business domains and contexts in which the software is to be engineered. This comes from business led conversations, domain storytelling and then we can evaluate data models presented to see how various integrated systems master and store these </p>
<h2 class="wp-block-heading" id="2-does-the-model-capture-behaviour">2. Does the model capture behaviour? </h2>
<p class="wp-block-paragraph">Domain models are richer than simple data models as they capture the behaviour and domain logic. An “anemic domain model” with CRUD style implementation is an anti-pattern as it lacks details about the “how”, “when”, “what-if” etc</p>
<p class="wp-block-paragraph">Consider an example of an application processing service where the need is to allow users to submit forms with some of their details. This is a common use case (can you identify this in your recent experience?) and in this scenario if purely start from a data model of a form with attributes of an applicant, their address, related contacts etc then when modelling this into a service with end up with a basic <em>accept and persist</em> type service. Our software has no inputs about any other processing to be done on the data leading us to believe we are done and shoving the hard-work to something else down the road. As a result one issue could be that there are multiple services acting on the same model (one for storing the other for processing etc) leading to the store and model becoming shared across the teams maintaining the services and coupling. We lose cohesiveness </p>
<p class="wp-block-paragraph">Now consider modelling the domain service with processing logic such as validation (what is the minimum required details, some address validation etc.) and business rules (applicant must be local, some date within the form must in current or in some range). This would lead to a domain service that was richer, deeper and cohesive. Changes would be managed by the maintainers of the service and the model would not leak outwards to other areas</p>
<h2 class="wp-block-heading" id="summary">Summary</h2>
<p class="wp-block-paragraph">Domain modelling is a process of understanding how to design the software based on business needs and consists of mapping not just the information but also the behaviour, rules and processing logic. Building domain models from a data model (from a system or some other construct) can miss the key ingredients to a good domain model leading to different implementations, ownership and fragmentation. It is therefore key to differentiate between the two and understand where both provide value – use domain modelling is it richer story about how to build software from a business perspective then understand how to apply/enrich a data model </p>
One of the smells when practicing DDD (Domain Driven Design) is when you are presented with a Data Model (extracted from an existing set of tables or constructed through rigorous but confirmed hypotheses) and asked to consider this as your Domain Model
Domain Model is not the same as a Data Model
This is an easy trap to fall into because both contain describe some information model and capture references. Yet, there are key differences and there are 2 key things that I would consider
1. Business led or Technology led model?
Ask who created the model?
A Domain Model is created in conversation with Business and Technical Domain experts. The key to this model islanguage – we capture nuances of language and the context. These help us understand there are subtle variations of the information model in different contexts
For example, if I describe the word “Cart” then you are curious as a domain modeller to ask me the context (Shopping-Cart, Gardening-Cart or Mario-Cart depending on Shopping, Gardening or Gaming contexts)
A domain story from business experts
In contrast a Data Model comes from technical point of view and may not capture behaviour and nuances in language. The risks are that the technical model may have generalised language leading to multiple contexts accessing the same model leading to coupling across these context which we want to avoid. We must evaluate the data model presented in the context of an organisation against the various business domains and contexts in which the software is to be engineered. This comes from business led conversations, domain storytelling and then we can evaluate data models presented to see how various integrated systems master and store these
2. Does the model capture behaviour?
Domain models are richer than simple data models as they capture the behaviour and domain logic. An “anemic domain model” with CRUD style implementation is an anti-pattern as it lacks details about the “how”, “when”, “what-if” etc
Consider an example of an application processing service where the need is to allow users to submit forms with some of their details. This is a common use case (can you identify this in your recent experience?) and in this scenario if purely start from a data model of a form with attributes of an applicant, their address, related contacts etc then when modelling this into a service with end up with a basic accept and persist type service. Our software has no inputs about any other processing to be done on the data leading us to believe we are done and shoving the hard-work to something else down the road. As a result one issue could be that there are multiple services acting on the same model (one for storing the other for processing etc) leading to the store and model becoming shared across the teams maintaining the services and coupling. We lose cohesiveness
Now consider modelling the domain service with processing logic such as validation (what is the minimum required details, some address validation etc.) and business rules (applicant must be local, some date within the form must in current or in some range). This would lead to a domain service that was richer, deeper and cohesive. Changes would be managed by the maintainers of the service and the model would not leak outwards to other areas
Summary
Domain modelling is a process of understanding how to design the software based on business needs and consists of mapping not just the information but also the behaviour, rules and processing logic. Building domain models from a data model (from a system or some other construct) can miss the key ingredients to a good domain model leading to different implementations, ownership and fragmentation. It is therefore key to differentiate between the two and understand where both provide value – use domain modelling is it richer story about how to build software from a business perspective then understand how to apply/enrich a data model
Alok brings experience in engineering and architecting distributed software systems from over 20 years across industry and consulting. His posts focus on Systems Integration, API design, Microservices and Event driven systems, Modern Enterprise Architecture and other related topics
View all posts by alokmishra