Hi Friends,
Welcome to the 202nd issue of the Polymathic Engineer newsletter.
This week, we are kicking off a new series of articles on microservices. In this issue, we will have a look at what they are, the benefits and costs they entail, and when it makes sense to use them.
Suppose that you’re building a food delivery platform. Customers browse menus, place orders, make payments, and receive a notification when the courier is on their way. Initially, all of this resides within a single codebase and is deployed as a single package.
If the platform is successful, you will keep adding components to it to satisfy an ever-growing list of business requirements. The components become increasingly coupled over time, and developers step on each other’s toes more frequently. Eventually, the codebase becomes complex enough that nobody fully understands every part of it, and implementing new features or fixing bugs takes a lot longer than it used to. A change to one component requires the entire application to be rebuilt and deployed. If the new version introduces a memory leak in one component, it takes down the process that hosts all the others. And reverting a deployment slows down every developer, not just the one who introduced the bug.
One way to deal with these growth-related challenges is to split the application into independently deployable services, each owning its own data, that talk to each other through APIs. This is what is known as a microservice architecture.
But here’s the point: a team of five people and a team of one hundred people experience the same difficulties. This article examines which of the two should take action to address them.
The outline is as follows:
- What makes a service a microservice
- Architecture follows the organization
- The monolith
- What you gain and what you pay
- Should you use microservices?
To learn technical skills, you must work on real projects. CodeCrafters is a great platform for that. You can build your own Redis, Kafka, DNS server, SQLite, HTTP server, or Git from scratch using your chosen programming language.
What makes a service a microservice
Microservices are services that can be deployed independently and are modeled around a business domain. In our food delivery platform, one microservice might handle orders, another payments, and yet another the menu catalog. Together, they make up the entire system, but each one is a building block that can be worked on and released on its own.
From the outside, a microservice is a black box. The service exposes its functionality over one or more network endpoints (like a REST API or a queue), and consumers, whether they’re other microservices or other kinds of programs, use this functionality via these networked endpoints. The language the service is written in, and the way it stores its data, are hidden. This is the old idea of information hiding, which David Parnas introduced in the early 1970s: hide as much as possible inside a component and expose as little as possible through its interface. The payoff is a clear separation between what can change easily and what is hard to change. Everything behind the endpoints can change freely, as long as the interfaces don’t change in a backward-incompatible way.
This separation is what makes independent deployability possible. The underlying idea is that you can make a change to the Orders service, deploy it, and release it to users without deploying any other microservices. The important thing is not that you can do it, but that this is how you release by default. To get there, the services must be loosely coupled, with explicit, well-defined, and stable contracts between them and nothing that forces two of them to change together. If you take only one thing from this article, get into the habit of deploying a single service into production without touching the others, and many good things will follow.
The choice people have the hardest time with is data. A microservice should not share its database with other services. If the Payment service needs information about an order, it should go and ask the Orders service for it. Hiding the database is what gives each service control over what is shared and what is private. The APIs between services create boundaries that are hard to violate, unlike the boundaries between components running in the same process. Don’t share databases unless you really need to, and even then do everything you can to avoid it.
You may have noticed that nothing in the definition says how big a microservice should be. “How big should it be?” is one of the most common questions people ask, which is no surprise given that the word “micro” is right there in the name. However, size is the least interesting property of this architecture. Lines of code don’t measure the size: what takes 25 lines in Java takes 10 in Python. James Lewis of Thoughtworks has been known to say a microservice should be as big as his head, meaning it should be small enough that a person can easily understand it. A better way to think about it is how much functionality a service encapsulates behind a small surface area. A service that doesn’t do much only adds operational overhead.
Someone familiar with Service-Oriented Architecture (SOA) might ask if SOA and microservices are different things. The answer is that microservices are a form of SOA, with firm opinions about where service boundaries go and with independent deployability at its core. Many SOA projects had small services that all shared one database and had to be deployed together. Service-oriented? Yes. But not microservices. You can think of microservices as a specific approach to SOA, just like Scrum is a specific approach to Agile.
Architecture follows the organization
Our food delivery platform started with the architecture most applications start with: a web UI, a backend holding the business logic, and a database. This is the classic three-tiered architecture, and its layers are commonly owned by different teams: a frontend team, a backend team, and a team of database administrators.
Now suppose you want to make a simple update to our functionality: let customers mark themselves as vegetarian so the platform can filter the menus accordingly. This small feature requires changing the UI to show the new option, the backend to expose and update the flag, and the database to store it. Three teams have to make a change each, and the three changes have to be deployed in the correct order.



