{{announcement.body}}
{{announcement.title}}

Microservices and Data Management

DZone 's Guide to

Microservices and Data Management

The fundamentals of microservices and how it helps in data management.

· Microservices Zone ·
Free Resource

Introduction

For pure frontend developers who doesn't have much exposure to backend or middleware technology, microservices are a vague thing. They might have high-level introduction. So, let us have some deep understanding of what microservices are, and how it is different from monolithic application data management. 

Monolithic and Microservice

In a monolithic application, all the stakeholders like all the business logic, routing features, middle-wares and Database access code get used to implement all the functionalities of the application. It is basically a single unit application. It has a lot of challenges in terms of scalability and agility. On the other side, in a microservice, all the business logic, routing features, middle-wares, and database access code get used to implement a single functionality of the application. We break down the functionalities to the core level and then connect to related services. So, the functionalities are actually dependent on related services only and does not get affected if there is an issue with other services. This helps to make the application agile, flexible, and highly scalable.  

Monolithic architecture


Microservices Architecture

Why Microservices

Independent DB for the Services

The very first important thing associated with microservices is that each functionality requires its own database and never connects to the database of other services. In a monolithic service, since you have a single database. if something goes wrong with it then the whole application gets crashed. But in microservice, since we have an independent database for each service, in case of any problem with any particular database, it certainly does not affect other services and your application does not crash as a whole. 

No Dependency on Schema

We have many services in our application and each service requires its own database. Hence, each database has its own schema or structure. But, if any service is connected to other service and shares the data and during development, the source database changes its schema and does not update the dependent services, then the service will not function correctly and may crash. So, there should be no dependency on databases.

Performance

Depending on the nature of service, we choose the appropriate type of DB. Some services are more efficient in specific database. So, creating a single database for all the services in the application might affect performance. In Microservice, since we have individual DB for each of the service, it is quite flexible, independent, and functions efficiently.

Data Management

Unlike the monolithic approach, in microservice, each functionality or service connects to its own database and never gets connected to other database. So, the big question arises of how we communicate between two services. It is quite generic in an application that we require to get some information based on the combination of many service outputs. But as a thumb rule, services dont communicate. Then what is the solution to this issue? Let us see, how data communicates between the services.

Communication Between Services

Communication between services

There are two communication strategies between the services:

Synchronous Communication

When services communicate with each other using direct requests to get the information.  Let us say we have a service request to get some information which is based on other services available in the complex application. In the sync communication, the service requests connection with other services and based on the response, it yields the information. It does not directly communicate with the individual DB of the other services. In this process, although we have individual DB for the service and services never connect to the same DB, the process takes time and responds slowly because it is dependent on various responses. Also, it may not get the required response if any of the services gets crashed on which it is dependent.

Asynchronous Communication

When services communicate with each other using events. Suppose we get a request to any service to perform a task; it simultaneously emits an event over to event bus as well to describe the task. Event bus then send that information to any service which requires that information. The service enters that information in its database. This process is called Async communication. With this approach the new service has no dependency on other services and the performance will boost up.

Conclusion

Although the concepts and architecture of microservices are complex in nature, it is rapidly being used in application development. It re-structures the application into micro-level services where each service has one single functionality. Services are never ever dependent on each other and so the whole application does not crash even though few of the functionalities do not work. It helps the application stay modular, flexible, and fast.

Topics:
data management, microservices archiecture, microservices benefits, microservices communication, monolith vs microservice

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}