Skip to main content

Microservices considered harmful


A recent trend in our industry is the software architecture move from a monolith app to microservices, often with a related blog post explaining how much better everything is after. A recent blog post by neobank Monzo explains that they have reached the crazy amount of 1500 microservices (a ratio of ~10 microservices per engineer), and details one of the many challenges it creates (spoiler: security). In this article, I will try to debunk two supposed "benefits" of microservices: modularity and scalabity.

A tentative definition

It's hard to find a proper definition for the term microservice. The most frequent definition I've read is functional: it would be a smaller-than-normal (thus micro) unit of functionality. This definition is illformed because we can always go deeper in this rabbit hole: Is performing an addition an unit of functionality? Should we have a standalone binary to do a simple arithmetic operation? Where do we draw the line?

I've read on r/programming a technical definition: a microservice is a badly named encapsulation technique. We already know functions, classes, modules, packages, libraries to achieve the purpose of encapsulating a service (= a unit of functionality); microservice would just be another one, with the defining difference that microservices are run as standalone binaries, and the communication between microservices is done over the network.

Fallacy #1: Microservices lead to cleaner code.

Modularity (or separation of concern) is an important goal of software engineering, and all mainstream programming languages offer several tools of various granularity to implement it. However, this is a very hard task and we often fail it leading to the dreadest spaggheti codebase.

The main difficulty of having a modular codebase is to identify the dependencies between each part of your product: this is not related to your codebase, but purely an intrinsic aspect of your product. The technical tools you have at your disposal don't help identifying dependencies, but only help to implement those dependencies. If your codebase has failed to achieve modularity with tools such as functions and packages, it will not magically succeed by adding network layers and binary boundaries inside it: you will end up with the spaghetti over HTTP codebase.

However, your codebase has now to deal with network and multiple processes. It creates a whole new set of additional problems to solve, and potential bugs to introduce:

  • Network failure (or configuration error) is a reality. The probability of having one part of your software unreachable is infinitely bigger now.
  • Remember your nice local debugger with breakpoints and variables? Forget it, you are back to printf-style debugging.
  • SQL transaction ? You have to reimplement it yourself.
  • Communication between your services is not handled by the programming language anymore, you have to define and implement your own calling convention (some languages acknowledge it and provide constructs to help like Ballerina).
  • Security (which service can call which service) is checked by the programming language (with the private keyword if you use classes as your encapsulation technique for example). This is way harder with microservices: the original Monzo article shows that pretty clearly.

Fallacy #2: Microservices lead to more efficient code.

There are two aspects of efficiency for software: performance and scalability.

For performance, it is obvious that language-agnostic API and network calls is less than ideal (this might be the reason why the video game industry is still safe from this whole microservice trend).

But in the web age, all the fuzz is about scalability (maybe not for good reasons, but this is a topic for another rant). We generally scale our services linearly by adding more servers, allocating X servers for our application. Splitting an application into microservices gives finer-grained allocation possibility; but do we actually need that ? I would argue that by having to anticipate the traffic for each microservice specifically, we will face more problem because one part of the app can't compensate for another one. With a single application, any part (let's say user registration) can use all allocated servers if needed ; but now it can only scale to a fixed smaller part of the server fleet. Welcome to the multiple points of failure architecture.

Conclusion

It is pretty clear that by using microservice as your level of encapsulation, you are loosing a lot of features provided either by your programming language or by your operating system. So why go down this road ? The main benefit is independency: this is the only level of encapsulation which allows you to develop, test and deploy services separately. It should be seen as an escape hatch from the comfort and safety of other encapsulations. This is the Rust's unsafe keyword of service programming.

Like the famous Considered Harmful paper from Dijkstra, the main point of this article is that microservices are overused and that there are technically better programming constructs for most of their use cases. If you need this independency for a social reason (like keeping a team of engineer independent of another), go for it but keep in mind that almost all technical challenges (code modularity, scalability, single point of failure…) will not be magically solved by using microservices.

Comments

Popular posts from this blog

The Difference Between LEGO MINDSTORMS EV3 Home Edition (#31313) and LEGO MINDSTORMS Education EV3 (#45544)

http://robotsquare.com/2013/11/25/difference-between-ev3-home-edition-and-education-ev3/ This article covers the difference between the LEGO MINDSTORMS EV3 Home Edition and LEGO MINDSTORMS Education EV3 products. Other articles in the ‘difference between’ series: * The difference and compatibility between EV3 and NXT ( link ) * The difference between NXT Home Edition and NXT Education products ( link ) One robotics platform, two targets The LEGO MINDSTORMS EV3 robotics platform has been developed for two different target audiences. We have home users (children and hobbyists) and educational users (students and teachers). LEGO has designed a base set for each group, as well as several add on sets. There isn’t a clear line between home users and educational users, though. It’s fine to use the Education set at home, and it’s fine to use the Home Edition set at school. This article aims to clarify the differences between the two product lines so you can decide which

Let’s ban PowerPoint in lectures – it makes students more stupid and professors more boring

https://theconversation.com/lets-ban-powerpoint-in-lectures-it-makes-students-more-stupid-and-professors-more-boring-36183 Reading bullet points off a screen doesn't teach anyone anything. Author Bent Meier Sørensen Professor in Philosophy and Business at Copenhagen Business School Disclosure Statement Bent Meier Sørensen does not work for, consult to, own shares in or receive funding from any company or organisation that would benefit from this article, and has no relevant affiliations. The Conversation is funded by CSIRO, Melbourne, Monash, RMIT, UTS, UWA, ACU, ANU, ASB, Baker IDI, Canberra, CDU, Curtin, Deakin, ECU, Flinders, Griffith, the Harry Perkins Institute, JCU, La Trobe, Massey, Murdoch, Newcastle, UQ, QUT, SAHMRI, Swinburne, Sydney, UNDA, UNE, UniSA, UNSW, USC, USQ, UTAS, UWS, VU and Wollongong.

Building a portable GSM BTS using the Nuand bladeRF, Raspberry Pi and YateBTS (The Definitive and Step by Step Guide)

https://blog.strcpy.info/2016/04/21/building-a-portable-gsm-bts-using-bladerf-raspberry-and-yatebts-the-definitive-guide/ Building a portable GSM BTS using the Nuand bladeRF, Raspberry Pi and YateBTS (The Definitive and Step by Step Guide) I was always amazed when I read articles published by some hackers related to GSM technology. H owever , playing with GSM technologies was not cheap until the arrival of Software Defined Radios (SDRs), besides not being something easy to be implemented. A fter reading various articles related to GSM BTS, I noticed that there were a lot of inconsistent and or incomplete information related to the topic. From this, I decided to write this article, detailing and describing step by step the building process of a portable and operational GSM BTS. Before starting with the “hands on”, I would like to thank all the pioneering Hackers and Researchers who started the studies related to previously closed GSM technology. In particul