Archive

The Dulin Report

Browsable archive from the WordPress export.

2022

In most cases, there is no need for NoSQL Apr 18, 2022 TypeScript is a productivity problem in and of itself Apr 20, 2022 Best practices for building a microservice architecture Apr 25, 2022 Good idea fairy strikes when you least expect it May 2, 2022 If you haven’t done it already, get yourself a Raspberry Pi and install Linux on it May 9, 2022 Most terrifying professional artifact May 14, 2022 Peloton could monetize these ideas if they only listen May 15, 2022 Am I getting old or is it really ok now to trash your employer on social media? May 25, 2022 There is no such thing as one grand unified full-stack programming language May 27, 2022 Automation and coding tools for pet projects on the Apple hardware May 28, 2022 Java is no longer relevant May 29, 2022 Good developers can pick up new programming languages Jun 3, 2022 Scripting languages are tools for tying APIs together, not building complex systems Jun 8, 2022 Keep your caching simple and inexpensive Jun 12, 2022 All developers should know UNIX Jun 30, 2022 Monolithic repository vs a monolith Aug 23, 2022 Why don’t they tell you that in the instructions? Aug 31, 2022 Using GNU Make with JavaScript and Node.js to build AWS Lambda functions Sep 4, 2022 Stop Shakespearizing Sep 16, 2022 The Toxic Clique Sep 28, 2022 Book review: Clojure for the Brave and True Oct 2, 2022 Why you should question the “database per service” pattern Oct 5, 2022 Why I am a poll worker since 2020 Nov 11, 2022 If we stop feeding the monster, the monster will die Nov 20, 2022 Things to be Thankful for Nov 24, 2022 Working from home works as well as any distributed team Nov 25, 2022 Should today’s developers worry about AI code generators taking their jobs? Dec 11, 2022

Why you should question the “database per service” pattern

October 5, 2022

Questioning experts is a good thing. I question the idea that in a single application, each service must have its database. I think the database per service concept has been quite damaging to software architecture for many years.



What problem is this pattern serving that cannot be solved by a modern relational database? Let’s examine




Services must be loosely coupled so that they can be developed, deployed and scaled independently

https://microservices.io/patterns/data/database-per-service.html



I agree, but that is not an argument for overcomplicating your database.




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.

https://microservices.io/patterns/data/database-per-service.html



Sure, but if your business logic involves transactions that span data owned by multiple services, perhaps the most reliable way to use transactions is to use RDBMS capabilities.




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 creditLimit and Orders to calculate the total amount of the open orders.

https://microservices.io/patterns/data/database-per-service.html



Again, if your business transactions need to query data owned by multiple services, you are complicating your life and productivity by separating a database per each service. I guarantee that even if you twist yourself into a pretzel at the onset of the project to avoid this, eventually, you will be pressured into supporting queries across services in a transactional fashion.




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.

https://microservices.io/patterns/data/database-per-service.html



To me, this reads as another argument for not splitting up the database.




Databases must sometimes be replicated and sharded in order to scale

https://microservices.io/patterns/data/database-per-service.html



A modern RDBMS can do that just fine.




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.

https://microservices.io/patterns/data/database-per-service.html



A modern RDBMS can do most of the above. As an architect, if you are sitting there in your silo creating a witch’s brew of a soup that involves multiple database technologies, perhaps you should re-examine both your sanity and your architecture.



I am not a fan of the database per service model. The correct pattern for the database model in a cloud-native environment is a data abstraction layer that hides the underlying database mechanics while allowing for transactions that span multiple services. The services should not know the architecture of the database, nor should they orchestrate their transactions.