Microservices and Design Granularity

When modeling, and designing microservices the granularity of individual service characteristic need to be carefully assessed and defined in support of achieving the goals, and benefits of microservices there are four granularity levels that apply to any type of:

service granularity.

-capability granularity.

-data granularity.

-constrained granularity.

of these four the server’s data and constrained granularity levels are of special importance to the microservices design we’ll start with taking a look at service granularity. the overall quantity of functionality encapsulated by a microservice determines the service granularity.

the level of service granularity is set by the service’s overall functional context, but not by the actual amount of functionality within the physically implemented service.  the larger the quantity of related functionality the coarser the service granularity as discussed later in this course a microservices functional context is generally based on a microtask meaning that it will typically have a narrow and more targeted functional context and that it will therefore have a finer-grained level of service granularity.

Service Granularity

let’s take a look at capability granularity a given microservice API comprises one or more capabilities the quantity of functionality encapsulated by a specific service capability determines the level of corresponding capability granularity. regardless of the overall level of service granularity, a microservice can contain a combination of fine and coarse-grained capabilities a get invoice capability. that processes entire business document may be considered gauss-grained whereas another microservice may expose a get header capability that only processes a subset of the business document which is more fine-grained, it is not uncommon for microservices to provide several variations of a get method with different levels of granularity note that these granularity levels are based on the scope of functionality not on the quantity of data being exchanged, for that we have another type of granularity which is data granularity. the quantity of data exchanged by a specific service capability determines the level of its data granularity, note that the data granularity away capability doesnt always correspond to the capability granularity a capability may be fine-grained because it performs a simple query however it’s data granularity may be coarse-grained because the quantity of information it retrieves is large a get capability that retrieves and returns entire business document will have a coarser level of data granularity than a get header capability that only returns a subset of the business document data let’s take a look at constraint granularity.

Constraint Granularity

the extent of validation logic detail defined for a given microservice capability determines the capabilities level of constrained granularity generally the more specific the constraints and the larger the number of constraints the more fine-grained the capabilities constrained granularity is microservice capabilities with less or broader constraints such as those that allow data ranges or are weakly typed are considered to have more of a coarse-grained level of constraint granularity because microservices are meant to be fault-tolerant and designed evolutionary overly fine constrained granularity can lead to incompatibility across API versions thereby hindering a microservices evolution just to note on services and granularity the illustration shows all four types of granularity and their influence on different aspects of service we can see that the design of a service is influenced by the different measures of granularity.

Add Comment