Microservices Design Patterns

Priyal Walpita
6 min readJul 9, 2018
Image result for microservices

With the constantly changing business models and services offerings, organizations frequently try to take off updates at a regular frequency, in some cases even various times a day. This necessity for the quick rollout of updates isn’t anything but difficult to be satisfied with a monolithic design which has firmly coupled framework. Today, Microservices architecture has developed as a solution to have the desired changes take off to applications in terms of scalability, accessibility, and nimbleness.

‘Microservices’ portrays a specific method of designing software applications as suites of autonomously deployable services. It has evolved from conventional service-oriented design with the free coupling of segments to decoupled service elements and infrastructure. Microservices area units work around business abilities and are freely deployable by totally robotized deployment machinery. The centralized management of these services is insignificant, which might be composed of various programming languages and might utilize different data storage technologies.

Microservices are small autonomous systems that give an answer that is distinct, unique inside the eco-system. It keeps running as a full-stack module and works together with different Microservices that are a piece of the eco-system. Sam Newman characterizes Microservices as “small, centered and completing one thing extremely well” in his book “Building Microservices.”

Microservices are made by slicing and dicing a single large monolithic system into numerous independent autonomous systems. It can likewise be an attachment peak add-on segment to work alongside the current system as another component or as a greenfield venture.

Most of the software designers and architects tend to use Microservices in their software designs. You can learn the basics of Microservices architecture from Martin Fowler’s. This blog series focuses on the design patterns that we can use when designing and implementing Microservices.

In this blog series, I am going to give you more knowledge on the key design principles of Microservices to make it as the desired solution to have a scalable, easy to maintain enterprise application. Let’s start this blog series…

  1. Microservices and Bounded Context
  2. Asynchronous Microservices
  3. API-based Microservices
  4. Data Consistency Across Microservices
  5. Using API Gateway to maintain centralized access
  6. Split Monolithic Databases Across Microservices
  7. Resilience in Microservices
  8. Define and Document Microservice Contracts
  9. Centralized Logging
  10. Cloud-Based Microservices Infrastructure
  11. Manage Configurations
  12. Registration and Discovery
  13. Monitor Microservices

Bounded Context

Scoping out the Microservices correctly is a crucial factor when we are designing a good Microservices architecture. A scope that ensures each component is loosely coupled and highly cohesive, making the overall design easy to change at any point or the overall architecture easy to scale out and change and deploy without any risk.

Your Microservices based architecture would end up in disaster if you are unable to make a proper separation of services. One of the main principals in Microservices is to change and deploy whilst at the same time minimizing the risk from change and deployment. This is achieved by services made up of small, loosely coupled, highly cohesive components. But how do we decide how small it is? We can use the Bounded Context to define the size and scope of a Microservice.

The Bounded Context concept came into the software design domain from the software design methodology called Domain Driven Design, which was originally introduced by Eric Evans.

Use of Bounded Context as a technique to define the scope of our Microservices can be seen as a strategic design pattern that we can use to design our Microservices architecture. And it should be used as a tool to guide the design of each one of our components throughout the whole process, during the development and during the maintenance of our software architecture. Before jumping into the Bounded Context, it is essential to get some insight about the DDD ( Domain Driven Design ).

Domain Driven Design

Microservices provide the capacity to isolate system ability into various domains utilizing Domain Driven Design standards. Its all about creating software that models real-world domains, which means you end up with software that consists of a design and models which represent the real-world problem you are trying to solve. One of the main advantages of this method is, it is using real-world domain terminology when we are designing the system instead of technical terms. This approach requires both domain experts and software experts to work together in order to model the software.

Any business domain will consist of multiple sub-domains and sub-functions and each will be represented by a bounded context. This segregation helps to build Microservice which can cater to that business sub-domain which we specified in the Bounded Context. Within a Bounded Context, there will be an internal language which describes all the models and components associated with that domain. This language is referred to as the Ubiquitous Language. The Bounded Context and Ubiquitous Language helps us to think that there’s a boundary around our Microservice and then it forces us to think about what’s actually inside the Microservice, i.e. within its context, and what’s outside that boundary outside of that context etc.. This helps us to create loosely coupled and highly cohesive Microservices.

Ubiquitous Language

Most of the software designs failed because of the distance between domain experts and software designers. Mainly they are speaking two different languages which caused this problem. The Ubiquitous Language bridges this gap by bringing both these entities into one common ground. In Domain Driven Design the Ubiquitous Language is considered as an agreed language between the domain experts and the software experts to help define the Bounded Context.

Image 1 : Bonded Context

According to the previous image, domain experts and the software experts define the Ubiquitous Language, which is closely related to the core concept.

The main goal of this language is to define a set of terms which are non-technical and are agreed between the domain experts and the software experts. This language is used as a very effective tool to work out which supports concepts relating to our core concept. Whatever the concepts that are not fitted into this language is considered as an out of context concept.

This out of context concept might fall into another Bounded Context.

To elaborate on this more, let’s think about a real-world scenario, a managed taxi service where you have riders, drivers, manager, and rides.

First of all, we need to identify our main concepts in our domain.

Image 2 : Define main concepts and sub-concepts

In the previous picture, the items that are denoted in green are the main concepts and blue ones are the sub-concepts. You can see clearly how we can segregate the Bounded Context. We also need to identify any supporting concepts which don’t quite fit the natural language of the core concept or where the supporting concept actually feels as if it lodges in the actual core concept. As an example, the driver in the Rides Bounded Context is more or less a supportive concept and ends up being a different Bounded Context. So we can integrate the Rides Bounded Context and the Driver Bounded Context using the Driver concept in the Rides Bounded Context.

From this example, you can understand how we can take a core concept and a Bounded Context and convert it into a Microservice and how as we take this stepped approach we can start building relationships with other Bounded Contexts, which basically shows you how your Microservice will interact with other Microservices.

Wouldn’t it be amazing if we learn more about Microservices design patterns in the next series? I will be publishing next blog very soon, in the meantime, if you have any query/concern then you can drop me an email on or send me a message on LinkedIn, or Twitter. I’m just a message away :)

Hoping to see you soon in the next post of this series.

--

--

Priyal Walpita

CTO @ ZorroSign | Seasoned Software Architect | Expertise in AI/ML , Blockchain , Distributed Systems and IoT | Lecturer | Speaker | Blogger