Data Modelling: The right steps

Douglas Rocha
4 min readNov 30, 2018

--

This is an article about how to use domain-driven design techniques to create data models [0]

There is a new client on the block and your boss is very happy with the profit perspectives. He invites every developer for this cool new product meeting and everyone starts to express their opinions about the project. You know that in the next few weeks you’ll have a new data model ready, I mean, this is the main expectation for these meetings.

The meeting starts with a list of requirements made by the client and it all goes nice and softly until someone shouts: “I think we are ready to draw the data model”. Now all developers are crazy, blasting entities and relationships on the blackboard and deciding which columns should each of those entities have as if entities could have columns…

If that is the reality of your data modelling meetings, then this article is for you.

Ubiquitous Language

Domain-driven design is a set of tools and techniques to model, implement and manage a knowledge domain. The first book, “Domain-Driven Design: Tackling Complexity in the Heart of Software (2004)” [1], was written by Eric Evans exactly 36 years after the term software engineering was firstly coined by NATO due to the “software crisis”. This means that it was created after more than three decades of knowledge gathering on the topic.

The first pages of the book express the need to design an ubiquitous language. There is no chance that a team of people working on a project will be able to develop good software without a ubiquitous definition of the domain-specific words, so it is good advice to focus on developing a common language to be used by the stakeholders before the beginning of the modelling process (that includes your clients). Once you do that, you are ready for the next step.

Conceptual Model

After having a strong ubiquitous language you will notice that most of the words represent an entity in your domain. Now it is time to start defining the relationships between these entities. Forget about tables, columns, attributes, cardinalities! All you want to do is understand how each entity relates to others.

Think of a mind map… With the ubiquitous language, you make your team understand what you are talking about and with the conceptual model you make your team understand the relationships, and if relationships they had in mind make any sense.

This is a good representation of what a conceptual model should look like [2]

Bounded Contexts

You are ready for the most important step: Planning software that is ready to grow. No kidding! Pay close attention to this.

Now that you understand all the possible relationships between entities, you start to have a grasp on how you can group entities that relate to each other. Each cluster of these is called a bounded context. They allow you to understand your domain as parts and also to build software as “little” blocks.

This is a context map that represents a knowledge domain composed by two bounded contexts [3]

What is the advantage of building software as little parts? Well… There are many benefits such as maintainability. Having small little pieces of software is much better than having a huge monolithic system. Another great advantage is the fact that we are part of a distributed computing revolution and bounded contexts are great candidates to become micro-services if your software grows a lot.

There is one great advantage that helps not only developers but the whole business. When you understand your bounded contexts, you are able to not only reduce maintainability costs but also to map how each context relate to another. The domain-driven design book aids developers and organizations by presenting strategies to solve the relationships between contexts. Some of them are:

  • Shared Kernel
  • Customer / Supplier
  • Published Language
  • Open Host Service
  • Anti-corruption Layer
  • Conformist
  • Separate Ways

I’ll talk about those in a future article. Remember that domain driven design is a tool for both developers and managers.

Finally…

Now that you understand your problem, its contexts and the relationships between entities and contexts, you are finally ready to model the attributes and make small adjustments to refine your data model. This step is called “Logical Data Model” and is exactly what enterprises tend to jump to when they have to model a new product. Jumping to that step is one of the greatest causes of requirements’ misunderstanding and bad quality implementations.

This is a logical data model. It has entities, relationships, cardinalities and attributes [4]

There are many more tools to help in the domain modelling process such as event storming, subdomain modelling and aggregates. The objective of this article is to help people understand that before writing relationships and attributes, one must first understand and “standardize” the knowledge of the domain.

I have seen many enterprises that fail to model domains correctly and consequently to deliver what the client really wanted. I really hope this can be of great support!

--

--

Douglas Rocha

Amazonian • Hacker • Former CTO at InvestPro • Cloud solutions expert • Enterprise Architect • Loves his wife, family and maths.