Reader small image

You're reading from  Building Microservices with .NET Core

Product typeBook
Published inJun 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781785887833
Edition1st Edition
Languages
Right arrow
Authors (3):
Gaurav Aroraa
Gaurav Aroraa
author image
Gaurav Aroraa

Gaurav Aroraa has done M.Phil in computer science. He is a Microsoft MVP, life time member of Computer Society of India (CSI), certified as a scrum trainer/coach, XEN for ITIL-F and APMG for PRINCE-F and PRINCE-P. Gaurav serves as a mentor at IndiaMentor, open source developer, contributor to TechNet Wiki co-founder of Innatus Curo Software LLC. In 19+ years of his career, he has mentored thousands of students and industry professionals. You can tweet Gaurav on his twitter handle @g_arora
Read more about Gaurav Aroraa

Lalit Kale
Lalit Kale
author image
Lalit Kale

Lalit Kale is a technical architect and consultant with more than 12 years of industry experience. Lalit has helped clients achieve tangible business outcomes through the implementation of best practices in software development. He is a practitioner of TDD and DDD, and a big believer in agile and lean methodologies. He has worked with several organizations, from start-ups to large enterprises, in making their systems successful, be it in-house or mission critical, with clients in the USA, the UK, Germany, Ireland, and India. His current interests include container technologies and machine learning using Python. He holds a bachelor's degree in engineering (IT).
Read more about Lalit Kale

Manish Kanwar
Manish Kanwar
author image
Manish Kanwar

Manish Kanwar completed his masters of science in computer applications from MD University, India, and is a cofounder of Innatus Curo Software LLC, with a presence in India. He has been working in the IT industry across domains for the last 17 years. He started exploring .NET right from the first release and has been glued to it ever since. His range of experience includes global wealth management (financial service industry, USA), life insurance (insurance industry, USA), and document management system (DMS), ECMS, India. Manish does his bit for the community by helping young professionals through the IndiaMentor platform.
Read more about Manish Kanwar

View More author details
Right arrow

Understanding the microservice architecture


The microservice architecture is a way to develop a single application containing a set of smaller services. These services are independent of each other and run in their own processes. An important advantage of these services is that they can be developed and deployed independently. In other words, we can say that microservices are a way to segregate our services so they can be handled completely independent of each other in the context of design, development, deployment, and upgrades.

In a monolithic application, we have a self-contained assembly of user interface, direct sale, and inventory. In the microservice architecture, the services part of the application changes to the following depiction:

Here, business components have been segregated into individual services. These independent services now are the smaller units that existed earlier within the self-contained assembly, in the monolithic architecture. Both direct sales and inventory services are independent of each other, with the dotted lines depicting their existence in the same ecosystem yet not bound within a single scope. Refer to the following diagram:

From the preceding image, it's clear that our user interface can interact with any of the services. There is no need to intervene in any service when a UI calls a service. Both the services are independent of each other, without being aware of when the other one would be called by the user interface. Both services are liable for their own operations and not for any other part in the whole system. Although much closer to the microservice architecture, the preceding visualization is not entirely a complete visualization of the intended microservice architecture.

Note

In the microservice architecture, services are small, independent units with their own persistent stores.

Now let's bring this final change so that each service will have its own database persisting the necessary data:

Here, User interface is interacting with those services that have their own independent storage. In this case, when a user interface calls a service for direct sales, the business flow for direct sales is executed independently of any data or logic contained within the inventory service.

The solution that the use of microservices provides has a lot of likely benefits, as discussed next:

  • Smaller codebase: Each service is small, therefore, easier to develop and deploy as a unit
  • Ease of independent environment: With the separation of services, all developers work independently, deploy independently, and no one is bothered about any module dependency

With the adoption of the microservice architecture, monolithic applications are now harnessing the associated benefits, as it can now be scaled easily and deployed using a service independently.

Messaging in microservices

It is very important to carefully consider the choice of the messaging mechanism when dealing with the microservice architecture. If this one aspect is ignored, then it can compromise the entire purpose of designing using the microservice architecture. In monolithic applications, this is not a concern as the business functionality of the components gets invoked through function calls. On the other hand, this happens via a loosely coupled web service level messaging feature, where services are primarily based on SOAP.  In the case of the microservice messaging mechanism, it should be simple and lightweight.

There are no set rules for making a choice between various frameworks or protocols for a microservice architecture. However, there are a few points worth consideration here. Firstly, it should be simple enough to implement, without adding any complexity to your system. Secondly, it should be lightweight enough, keeping in mind the fact that the microservice architecture could heavily rely on interservice messaging. Let's move ahead and consider our choices for both synchronous and asynchronous messaging along with the different messaging formats.

Synchronous messaging

When a timely response is expected from a service by a system and the system waits on it till a response is received from the service, it is synchronous messaging. What's left is the most sought-after choice in the case of microservices. It is simple and supports HTTP request-response, thereby leaving little room to look for an alternative. This is also one of the reasons that most implementations of microservices use HTTP (API-based styles).

Asynchronous messaging

When a system is not immediately expecting a timely response from the service and the system can continue processing without blocking on that call, it is asynchronous messaging.

Let's incorporate this messaging concept into our application and see how it would change and look:

Message formats

Over the past many years, working with MVC and the like has got me hooked on the JSON format. You could also consider XML. Both the formats would do fine on HTTP with the API style resource. There are easily available binary message formats in case you need to use one. We are not recommending any format; you can go ahead with any of the selected message formats.

Previous PageNext Page
You have been reading a chapter from
Building Microservices with .NET Core
Published in: Jun 2017Publisher: PacktISBN-13: 9781785887833
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Gaurav Aroraa

Gaurav Aroraa has done M.Phil in computer science. He is a Microsoft MVP, life time member of Computer Society of India (CSI), certified as a scrum trainer/coach, XEN for ITIL-F and APMG for PRINCE-F and PRINCE-P. Gaurav serves as a mentor at IndiaMentor, open source developer, contributor to TechNet Wiki co-founder of Innatus Curo Software LLC. In 19+ years of his career, he has mentored thousands of students and industry professionals. You can tweet Gaurav on his twitter handle @g_arora
Read more about Gaurav Aroraa

author image
Lalit Kale

Lalit Kale is a technical architect and consultant with more than 12 years of industry experience. Lalit has helped clients achieve tangible business outcomes through the implementation of best practices in software development. He is a practitioner of TDD and DDD, and a big believer in agile and lean methodologies. He has worked with several organizations, from start-ups to large enterprises, in making their systems successful, be it in-house or mission critical, with clients in the USA, the UK, Germany, Ireland, and India. His current interests include container technologies and machine learning using Python. He holds a bachelor's degree in engineering (IT).
Read more about Lalit Kale

author image
Manish Kanwar

Manish Kanwar completed his masters of science in computer applications from MD University, India, and is a cofounder of Innatus Curo Software LLC, with a presence in India. He has been working in the IT industry across domains for the last 17 years. He started exploring .NET right from the first release and has been glued to it ever since. His range of experience includes global wealth management (financial service industry, USA), life insurance (insurance industry, USA), and document management system (DMS), ECMS, India. Manish does his bit for the community by helping young professionals through the IndiaMentor platform.
Read more about Manish Kanwar