I am reading Eric Evan's Domain Driven Design, and I encountered this concept on p108. I am having a hard time grasping the concept, in spite of the explanations mentioned on the pages 107 and 108.

Here is an excerpt of the topic from the book:

Medium-grained, stateless SERVICES can be easier to reuse in large systems because they encapsulate significant functionality behind a simple interface. Also, fine-grained objects can lead to inefficient messaging in a distributed system.

As previously discussed, fine grained domain objects can contribute to knowledge leaks from the domain into the application layer, where the domain object's behavior is coordinated.

Can somebody explain to me what is granularity so I can understand more what is being described in the excerpt above?

  • 1
    This is more a question about the English language itself. When we speak of something being granular when we are not talking about grains of sand, sugar, salt, etc, then we are talking about how finely detailed something is, or how specific it is. Lower granularity means fewer details or being less specific. Higher granularity means more details or more specific. The word "animal" is not as granular as "horse," which is not as granular as "thoroughbred" (a breed of horse). – Greg Burghardt Jan 11 at 14:24
  • I see. I thought it is something adherent to software design that I have never encountered. Eric uses this term very often in that section, so I thought it is a way for categorizing services and domain objects. Thank you for clearing this up. – TambaySaPinas Jan 11 at 17:10

Coarser and finer grained means implementing more or less functionality respectively. It is somewhat related to the size too.

So a "fine grained" service is something that does very little. Like a service that just multiples two numbers. A "coarse grained" service is something that does something more complex, like booking a room in a hotel.

A "medium grained" service is usually something near the middle of this scale. Like a service that books only the money from your credit card but doesn't do anything else. It is very much subjective of course, and depends on the scales involved in your project.

What he is saying there, if you use finer grained services/objects than obviously you need to communicate more because you need to speak to more services/objects. This also means that you are exposed to a lot more knowledge, because you have to understand some data and the choreography between calls.


Think sugar

  • There is raw sugar, it has a big grain.
  • Refined or white sugar, has a smaller grain.
  • Icing sugar, has a very small grain, it looks like dust.

For a computer

Granularity is talking about how much is in a thing, when you look at it from a given perspective.

  • An application has a coarser grain than an expression.
  • An application has a finer grain in comparison to a cloud.

From this perspective you could call an application medium grained.

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.