• Application development company
  • Application development company
  • Application development company
  • Application development company
  • Application development company
Application development company
Application development company

Unni Mohan

Digital Marketing Manager

Application development companySep, 2020
Application development company8 min read


Microservices Database Management – What You Should Know

It is an accepted fact that microservices architecture transforms the process, practices, and outcomes of software development in many ways. It is the inability of monolithic architecture in meeting the demands of modern applications that led to the development of microservices. According to an O’Reilly survey, most businesses (about 92 percent of the respondents) that have adopted microservices architecture for their organization have experienced some amount of success. However, one of the challenges posed by this architecture is the maintenance of data consistency across microservices.

In this post, we will discuss in detail as to how we can make microservices database management more effective. Besides, we will discuss aspects such as patterns you should use to solve data decentralization issues, how you can make services store more data without compromising their independence, and the best microservices database model for an application development project.

Microservices Database Management Challenges

In the case of a monolithic application, data is shared with different components of the app from a single database. On the other hand, data ownership is decentralized in the case of a microservices app and each autonomous service separately stores data that it needs to perform its function. As a result, one service cannot modify the database of another service. 

Irrespective of the type of application you create, microservices have to interact with each other and share data so as to eliminate consistency issues such as data duplication. As ACID transactions cannot be used in the case of microservices, it is a challenging task to implement transactions and queries that need interaction between different services.

5 Common Data Management Patterns for Microservices

The best strategy you can employ to overcome the challenges with respect to the management of databases is using different types of microservices database patterns that are available. Five of the commonly used patterns are discussed below:

Data Management Patterns for Microservices

#1: Database-per-Service pattern

The Database-per-Service pattern is the best choice when scaling and testing specific microservices as it offers the flexibility to choose a database. Since the databases remain isolated from each other, this pattern makes use of APIs to establish communication or exchange data. However, this pattern may not be suitable for larger and complex applications as there will be many microservices databases to deal with. Further, the successful execution of business logic becomes difficult as an API has to intervene and fetch the data and interact with different databases. As such, the database per-service pattern is the right choice for apps with limited scope.

Take a look at how SoundCloud has implemented microservices architecture. Read our blog titled “The Journey into Microservices at SoundCloud”.

#2: Saga pattern

There are two parts to the Saga pattern. There are:

Choreography-based Saga – Communication happens through the exchange of events.
Orchestration-based Saga – Saga participants are invoked with the help of centralized control and using requests/responses.

Saga pattern

In the case of applications with multiple transactions, the saga pattern is the best microservices database management option. For imagine, imagine that a customer places an eCommerce order. Two services – order service and customer service – will interact with each other. The saga communicates with the eCommerce store via the order service to manage the order placement events. On getting confirmation, the order service sends the reply. The saga approves or rejects orders based on the reply. If approved, the order status is communicated to the customer with the expected delivery date once the payment is completed. If not, an apology message is sent to the customer.
#3: API Composition Pattern

This pattern works by way of join in-memory operation. It disturbs the other services for performing the tasks. A query is implemented by invoking specific services that have the required data and combining the results. The API composer then extracts data from different services. However, this pattern may not be the right choice for some queries. This is because its in-memory joins are inefficient when dealing with big datasets.

API Composition Pattern

#4: CQRS Pattern

The command query responsibility segregation or CQRS pattern implements queries by way of view databases. In addition, it enables the separation of concerns, meaning it differentiates commands and queries. While query-side modules handle queries, keeping their data synchronized with that of the command-side, the command-side modules manage the operations.

CQRS can be used within a service to define queries. It queries a database and keeps it updated by subscribing to events that are published by the services that own data. The benefit of using this pattern is that it maintains a log of the events in databases along with the messaging queue as and when the user updates data.


#5: Event Sourcing Pattern

According to experts, the event sourcing pattern is the best database for microservices as it offers the right solution. Event sourcing refers to the changing state of activity when an event is generated or added to the event list. In addition to replaying the events that have already been performed within an application, it stores and keeps an events list and uses it to complete actions. This pattern makes use of APIs for retrieving and adding events and enabling services to subscribe to events.

Scalable applications make use of the event sourcing pattern for microservices database management. This is because they need multiple operations to be completed within a fraction of seconds and cannot waste time reconstructing events from scratch.

Event Sourcing Pattern

Shared Database Anti-pattern

Though it is possible to create a single microservices database that each service can access with the help of local ACID transactions, you need to think twice before implementing the same. This is because you stand the risk of losing the best features of microservices such as services independency and loose coupling. Besides, the time needed to coordinate services will be much more. Further, services can experience run-time problems and even block each other. Furthermore, a database failure can lead to a system shutdown down.

To know more about what is involved when moving your application to a microservices architecture, please download and read our eBook “Porting from Monolith to Microservices – Is the Shift Worth It

Are you looking for a microservices vendor? Call SayOne or drop us a note!

How to Choose a Microservices Database

The market currently offers several database options. However, it is important to choose the right one for your microservices application project. The first step is to pick the approach to create the database model. The two options available are:

  • Polyglot persistence
  • Multi-model databases

Polyglot persistence – Microservices architecture enables the use of a variety of data storage technologies for different services. In simple terms, a development team has the freedom to choose the persistence technology that is best suited to meet the needs of its services.  

Multi-model databases – The multi-model database approach supports more than a single abstraction, meaning you can have a single multi-model database but the data model for each service will be different. 

The multi-model approach offers operational simplicity when there is only one platform. Polyglot persistence, on the other hand, is the best option for microservices if the application is not very complex. However, the good news is that you can combine these approaches within many services.  

How to Choose a Microservices Database

Having said that, how do you choose the right database technology for your application that uses microservices? You just need to find answers for a couple of questions:

  • What types of data need be stored?
  • What kind of support does the microservices database require?

Non-relational Databases

A few of the non-relational databases (NoSQL) that support different types of data models and stored data are listed below. Microservices allow you to combine many of them.

Document database – This database stores and queries data as JSON-like documents. It is an intuitive data model. Further, a document database is scalable since it is a distributed system. Document databases are best suited for storing catalogs and content management.  

Key-value database – In a key-value database, data is stored by employing the key-value method. This means that a key-value represents a set of data. This database is suitable for session-oriented applications. This is because of its ability to process large amounts of data fast.

Graph-based database – A graph-based database makes use of graph structures for queries with nodes, properties, and edges to represent as well as store data. The graph relates stored data to a collection of edges and nodes with the edges representing the relationship between the nodes. Graph databases are used for fraud detection and in recommendation engines and social networks.

Column-based database – In this case, data is stored in columns, making it easier to access data than when it is stored in rows. A column-based database is used for creating a data warehouse. A wide column store is best suited for processing Big Data.

Relational databases

It is not a good idea to use a single relational database when developing a microservices application for the first time. However, you will have to use one when working on an existing monolith. This is because you cannot abandon the existing infrastructure when in the process of switching to microservices. You can start building the microservices with the available database and then slowly split it into many small services. Further, it is possible to use a relational database if are you are planning to apply polyglot persistence. This database is the right option for a service designed for managing low volume stable data.

Take Away

If your goal is to develop a robust application, it is important to implement a solid microservices data management plan. The best place to start is by choosing the right microservices data management pattern. The next step is to leverage different approaches and create data models and stores. The last step is to choose a microservices database that caters to the needs of each service.

How SayOne Can Help

Why Choose SayOne Technologies

Experts at SayOne Technologies can help you move your application to the microservices architecture in the most seamless manner without impacting your current operations. We can also design the application in such a way that it is easy to maintain and scale up as and when needed. The key factors that have helped become the best microservices solutions providers are:

  • Focusing on domain-driven design to avoid failure
  • Designing scalable microservices solutions
  • Ensuring effective microservices database management
  • Enabling continuous delivery of updates through the DevOps approach

Are you thinking of shifting to microservices to help your business grow? Call SayOne today!

Application development company

Choose the best microservices vendor and trim the cost

A majority of the big corporations in the world are going the microservices way. Microservices are small independent but interconnected services that make up an application. This is unlike the earlier approach, when companies functioned with a single larg

Application development company

Porting from Monoliths to Microservices

Monolith means ‘composed in just one single piece’. A monolith application with reference to software is today a single-tiered application package that has all the different components combined into one behemoth.

Application development company

Focus on your core business while you outsource your app developer

  • Risk-Free trial and Zero Recruitment Charges
  • 100% dedicated developers for flexible custom application development

Need top engineers for your team.
Got a project on your mind

We collaborate with visionary leaders on projects that focus on quality and require the expertise of a highly-skilled and experienced team.