DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Practical Transaction Handling in Microservice Architecture
  • Optimize AWS Solution Architecture for Performance Efficiency
  • Diving Into Reactive Microservices
  • Navigating and Modernizing Legacy Codebases: A Developer's Guide to AI-Assisted Code Understanding

Trending

  • Strategies for Securing E-Commerce Applications
  • Data Lake vs. Warehouse vs. Lakehouse vs. Mart: Choosing the Right Architecture for Your Business
  • Designing AI Multi-Agent Systems in Java
  • Yet Another GenAI Nightmare: Seven Shadow AI Pitfalls to Avoid
  1. DZone
  2. Data Engineering
  3. Databases
  4. Breaking the Monolithic Database in Your Microservices Architecture

Breaking the Monolithic Database in Your Microservices Architecture

As you break down your monolithic codebase to move to microservices, don't forget about your database. Learn how to break down your database.

By 
Samir Behara user avatar
Samir Behara
DZone Core CORE ·
Sep. 12, 18 · Tutorial
Likes (34)
Comment
Save
Tweet
Share
117.9K Views

Join the DZone community and get the full member experience.

Join For Free

When you are decomposing your application to adopt microservices architecture, it is important to focus on the monolithic database. You will need to come up with a solid strategy to split your database into multiple small databases aligned with your applications. In short you need to decouple your applications/services from using a single monolith shared database.

You should design your microservices architecture in such a way that each individual microservice has its own separate database with its own domain data. This will allow you to independently deploy and scale your microservices.

Traditional applications have a single shared database and data is often shared between different components. We all have worked with such databases and have found the development to be simpler since the data gets stored in a single store. But there are multiple issues with this database design.

Problems With Monolithic Database Design 

1. The traditional design of having a Monolithic Database for multiple services creates a tight coupling and inability to deploy your service changes independently. If there are multiple services accessing the same database, any schema changes would need to be coordinated amongst all the services, which, in the real world, can cause additional work and delay in deploying changes.

2. It is difficult to scale individual services with this design since you only have the option to scale out the entire monolithic database.

3. Improving application performance becomes a challenge. With a single shared database, over a period of time, you end up having huge tables. This makes data retrieval difficult since you have to join multiple big sized tables to fetch the required data.

4. Most of the times you have a relational store as your monolith database. This constraints all your services to use a relational database. However, there will be scenarios where a No-SQL datastore might be a better fit for your services and hence you don't want to be tightly coupled to a centralized datastore.

How to Handle Your data in a Microservice Architecture

Each microservice should have its own database and should contain data relevant to that microservice itself. This will allow you to deploy individual services independently. Individual teams can now own the databases for the corresponding microservice.

Microservices should follow Domain Driven Design and have bounded contexts. You need to design your application based on domains, which aligns with the functionality of your application. It's like following the Code First approach over Data First approach - hence you design your models first. This is a fundamentally different approach than the traditional mentality of first designing your database tables when starting to work on a new requirement or greenfield project. You should always try to maintain the integrity of your Business model.

While designing your database, look at the application functionality and determine if it needs a relational schema or not. Keep your mind open towards a NoSQL DB as well if it fits your criteria.

Databases should be treated as private to each microservice. No other microservice can directly modify data stored inside the database in another microservice.

In the below image, the Order Service won't be able to update the Pricing Database directly, it can only access it via the microservice API. This helps you to achieve consistency across different services.

Event-Driven Architecture is a common pattern to maintain data consistency across different services. Instead of waiting for an ACID transaction to complete processing and taking up system resources, you can make your application more available and performant by offloading the message to a queue. This provides loose coupling between services.

Messages to the queues can be treated as Events and can follow the Pub-Sub model. Publishers publishes a message and is not aware of the Consumer, who has subscribed to the event stream. Loose coupling between components in your architecture enables to build highly scalable distributed systems.

Handling database changes in your journey from Monolith to Microservice is challenging. In this article, we understood the problems with Monolithic Database Design and how you can handle your data in a microservice architecture. Please let me know if you have any questions and I will be happy to discuss further.

For more information about Architecture for Containerized Applications, please download the free ebook provided by Microsoft here.

Relational database microservice Architecture

Published at DZone with permission of Samir Behara, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Practical Transaction Handling in Microservice Architecture
  • Optimize AWS Solution Architecture for Performance Efficiency
  • Diving Into Reactive Microservices
  • Navigating and Modernizing Legacy Codebases: A Developer's Guide to AI-Assisted Code Understanding

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!