Hot Shot 010 – Dealing With M/SOA Data (Part 2) [Podcast]

DZone 's Guide to

Hot Shot 010 – Dealing With M/SOA Data (Part 2) [Podcast]

Part 2 of this podcast on data in microservice architecture discusses the database architecture in microservice applications.

· Microservices Zone ·
Free Resource

These are my verbatim notes from the PEAT UK podcast: 

Hello there once again and welcome to another hot shot. My name is Peter Pilgrim, DevOps specialist, Java enterprise and platform engineer, and Java Champion.

What’s the database architecture in a microservices application?

In true independent microservices, they are designed and built to follow the Single Responsibility Principle (Robert Martin), which is the idea that a software function, class, package or aggregate module does not one thing well and only one thing well.

* []

The single responsibility principle is a computer programming principle that states that every module or class should have responsibility for a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. Robert C. Martin expresses the principle as, “A class should have only one reason to change.”[1] 

Therefore the SRP implies the microservices must be loosely coupled so that they can be developed, deployed and scaled independently

Some business transactions must enforce invariants that span multiple services. For example, the Place Order use case must verify that a new Order will not exceed the customer’s credit limit. Other business transactions, must update data owned by multiple services.

Some business transactions need to query data that is owned by multiple services. For example, the View Available Credit use must query the Customer to find the credit limit and Orders to calculate the total amount of the open orders.

Some queries must join data that is owned by multiple services. For example, finding customers in a particular region and their recent orders requires a join between customers and orders.

Different services have different data storage requirements. For some services, a relational database is the best choice. Other services might need a NoSQL database such as MongoDB, which is good at storing complex, unstructured data, or Neo4J, which is designed to efficiently store and query graph data.

Ideally, each microservices in your application should be its own copy of a database that only the specific service can access. In other words, one microservice has a private database. Let’s make it absolutely clear. Each instance of a microservice class has ownership of database and when I use the term database it is very abstract meaning. The database is a simply a persistent store and it could be either RDBMS, or a NoSQL or Graph database or some other durable storage mechanism. So here I am talking a say three instances of a microservice an inventory warehouse payment processor thing access a distributed store. So visualize this for a moment.

Let’s say, we need to handle a spike then we could double the number of instances to our inventory warehouse payment microprocessor service and then we have 6 instances talking to our instance. We can double this again to 12 communications, and double it again 24 communications (or connections). Now, can we actually feel the pressure on 48 persistent connections from our Java microservices onto our so-called database?

Precisely, because the issue is that databases need to scale and still be atomic, consistent, isolated and durable with our very private customer data including yours and mine.

So in my experience, people have different ideas of a microservice persistent database. For some the ideal is too much, a customer might, for instance, look to AWS RDS Aurora for a solution because they know it is based on MySQL and Amazon cites this server endpoint as reliably distributed such that it scales. The MySQL workbench works with a remote Aurora RDS just as well as a local database on your workstation or on your firm’s on-premise datacenter. Because the AWS RDS can be treated as a distributed database server with multiple schemas, users and tables shared across microservice instances that can be attractive for customers. The drawbacks are obviously Amazon charges the cost and of course there are concerns about privacy and security of customer data.

data ,microservices ,software architecture

Published at DZone with permission of Peter Pilgrim , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}