{"id":12244,"date":"2019-02-10T16:09:00","date_gmt":"2019-02-10T14:09:00","guid":{"rendered":"https:\/\/mozaicworks.com\/?p=9999"},"modified":"2019-02-10T16:09:00","modified_gmt":"2019-02-10T14:09:00","slug":"modular-monolith-microservices","status":"publish","type":"post","link":"https:\/\/mozaicworks.com\/blog\/modular-monolith-microservices","title":{"rendered":"Modular Monolith Or Microservices?"},"content":{"rendered":"
It\u2019s impossible to ignore the topic of microservices today. We hear about them from social media, conferences, specialized websites, books, framework vendors, communities, colleagues. It seems like they\u2019re the only way to go.<\/p>\n
But are they? To answer this question, we first need to explore why are microservices so useful, what are their downsides and what are the alternatives.<\/p>\n
organizations which design systems … are constrained to produce designs which are copies <\/em>of <\/em> the communication structures of these organizations \u2014 Melvin E. Conway<\/em><\/p>\n Conway\u2019s Law has been first stated in 1967, and it has been proven empirically again and again. To understand it, let\u2019s discuss a few examples of its application:<\/p>\n Fred George started one of the first microservices projects with a big challenge<\/strong>: the work had to be organized in a way that allowed adding developers fast<\/strong>. He decided to use Conway\u2019s Law to their advantage, and create an architectural structure that allowed adding pairs of programmers to the development. The only option was to create many small services that communicated asynchronously and that were completely independent of each other, each developed by a pair of programmers. Enter microservices.<\/p>\n According to Fred George, they followed very specific rules for the architecture of the microservices. They started with a long session of domain modelling (about two weeks), that resulted into bounded contexts* and then into well-defined services. Each service:<\/p>\n In addition, code duplication between services is ignored. Otherwise, libraries will be extracted that increase deployment complexity and can lead to dependency hell.<\/p>\n These constraints allow for independent development by a lot of programmer pairs. Architecture and Conway\u2019s Law work hand in hand, helping the development go faster.<\/p>\n In conclusion, microservices are useful because of two things:<\/p>\n In addition, microservices can scale very easily <\/strong>and minimize spending on the cloud<\/strong>. The reason is that when load increases, more specific instances can be started at a minimal cost.<\/p>\n As we can see from the industry examples, these criteria apply very well for large projects that need to scale quickly. So if you need to start such a project, by all means, use microservices. But if you don\u2019t need to scale that quickly, there are easier ways. The reason is that microservices, like any architectural approach, are a trade-off.<\/p>\n Microservices have one important downside and can lead to one huge architecture mistake.<\/p>\n The downside is that microservices architecture leads to huge complexity increases for deployment and operations<\/strong>. Deploying one monolith is very different from deploying 100 or 1000 separate services. Monitoring and de-bugging then become a very difficult job. There are solutions, but each adds to costs and complexity. This investment might not pay o for smaller products.<\/p>\n The architecture mistake is to create microservices that directly depend on other microservices. This is just a re-creation of the dependency hell problem in deployment. If dependencies are hierarchical, changing a service propagates and require a lot of redeployments. Instead, aim for services that completely encapsulate one atomic change. This is the hardest thing to do about microservices; no wonder it took Fred George\u2019s team weeks to figure it out (and probably a lot more time after starting the development).<\/p>\n<\/div>\n<\/div>\n<\/div>\n There is an alternative to microservices, one that we used successfully for eventriX<\/a>: the modular monolith.<\/p>\n The idea of a modular monolith is to preserve the idea of encapsulation from above but deploy it in a different manner. We don\u2019t have to deploy a module as a service until we need to scale it. Instead, modules can be deployed as libraries, plugins, namespaces etc., resulting into one file that can be very easily deployed, monitored and debugged. As long as we follow a good modular structure inside the monolith, we can easily extract a service.<\/p>\n So how can we structure such a monolith? It obviously depends on the application. In the case of eventriX<\/a>, we follow a few clear rules:<\/p>\n All these rules allow us to quickly extract separate services or plugins if needed while maintaining the operational complexity at a minimum.<\/p>\n We have found microservices<\/strong> to be a great idea for large projects that need to scale quickly<\/strong> and save money when the load increases. But they also add huge operational complexity. We\u2019ve also seen that the most complex part of developing microservices is getting the modularity right. But teams who master modular architecture have more than one option.<\/p>\n<\/div>\n<\/div>\n<\/div>\n A modular monolith or a well-thought combination between plugins, modular monoliths and libraries allow fast development while maintaining low complexity. They also allow evolving to a more appropriate architecture when the need appear since logical modules can easily be extracted into physical modules.<\/p>\n The decision between microservices and modular monolith is not easy. It requires careful consideration of the trade-offs and of the context. It\u2019s up to the person(s) playing the role of the architect to end the best way. We hope this article helps you reach a decision.<\/p>\n Modularity is a core module (pun intended) of our Software Architecture Principles<\/a> workshop. If you need something specific related to architecture, let us know<\/a>. <\/em><\/p>\n<\/div>\n<\/div>\n *Bounded contexts are a core pattern in Domain Driven Design, grouping related domain entities<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":" It\u2019s impossible to ignore the topic of microservices today. We hear about them from social media, conferences, specialized websites, books, framework vendors, communities, colleagues. It seems like they\u2019re the only way to go. But are they? To answer this question, we first need to explore why are microservices so useful, what are their downsides and […]<\/p>\n","protected":false},"author":1,"featured_media":10003,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[1147,1103],"tags":[1403,1404,1405,1406,1407,1338],"acf":[],"_links":{"self":[{"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/posts\/12244"}],"collection":[{"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/comments?post=12244"}],"version-history":[{"count":0,"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/posts\/12244\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/media\/10003"}],"wp:attachment":[{"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/media?parent=12244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/categories?post=12244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mozaicworks.com\/wp-json\/wp\/v2\/tags?post=12244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
A few rules for microservices<\/h2>\n
\n
Why are microservices useful?<\/h2>\n
\n
A downside and a huge mistake<\/h2>\n
Modular monolith<\/h2>\n
\n
Conclusion<\/h2>\n