Escaping monolithic hell
FTGO's single big application now slows down every release, cannot scale its busy parts alone, is stuck on old technology, and falls over completely when one module has a bug. This chapter shows why that happens, when a monolith is still the right choice, and what splitting into microservices gives and takes.
key idea / coordinator service / good path in progress / watch out problem / failure neutral
FTGO (Food To Go) is a food-delivery company. Customers order from restaurants, the kitchen prepares the order, a courier delivers it, and the card is charged. FTGO built all of this as one program, a monolith: one codebase, one database, one deployable package. That was a good idea at the start. The business grew, the code and the team grew with it, and the program that once made FTGO fast now holds it back.
Why does a successful monolith turn into "monolithic hell", and is splitting it the cure? By the end you can name the pains of a big monolith, tell a modular monolith from a distributed one, explain what makes a microservice, weigh the gains against the costs, and decide whether and where FTGO should start.
FTGO's monolith slows everyone down
The delivery team has a one-line fix for the delivery-time estimate. It must wait for the next release, because every change ships in the same package as Orders, Payments and Restaurants. The build and the test run take a long time, so releases happen rarely and are risky. At lunch peak, FTGO must copy the whole application, reporting code included, just to handle more orders. Last month a memory leak in the notification code crashed the process, and customers could not place orders at all. And the framework the app is built on is years old, but rewriting everything at once to escape it is out of the question.
This is not a sign of bad developers. It is what happens when one program carries a growing business.
Think of a constrictor knot: the harder the business pulls (more users, more data, more developers), the tighter the monolith pulls back. Five pains show up again and again:
| Pain | What it looks like at FTGO |
|---|---|
| Coupling | Module boundaries fade over the years. A change to restaurant menus breaks customer login. |
| Team autonomy | Many developers in one codebase: merge conflicts, coordinated releases, and a team that is hard to grow. |
| Release cycle | Every release must validate and deploy everything, so even the delivery fix waits. |
| Scaling | The whole app is copied to scale one busy part, and the one database can only grow by buying a bigger machine. |
| Old stack | The technology is outdated, and replacing it means replacing everything at once. |
The obvious reaction is "split it up". But splitting is expensive and hard to undo. Before cutting anything, FTGO must ask a sharper question: is the monolith itself the problem, or the way it is built?
Is the monolith the problem? Three kinds of monolith
"Monolith" is not a synonym for "bad code". A system is a monolith when all of it must be deployed together. That covers three common shapes, and only one of them is a trap.
FTGO's Orders code reads straight from the Inventory and Reports tables, Checkout calls into Delivery internals, and nobody can say which module depends on which. The team blames "the monolith". But a rival company runs one deployable app with clean modules and ships happily every day. What is the difference?
| Kind | Good | Watch out for |
|---|---|---|
| Single-process | Simple to run, test and debug | Everyone shares one codebase |
| Modular | Parallel work on separate modules, simple deployment | The database is rarely split the way the code is |
| Distributed | Few: it is a distributed system and a monolith at once | Tight coupling, no information hiding, lockstep releases |
FTGO's code is the first kind gone wrong: a patchwork monolith, also called a big ball of mud. The rival runs the second kind. Both are one deployable unit; only the visibility of the dependencies differs.
Keep one deployable unit, but give it explicit modules with clear interfaces, and stop modules from reaching into each other's code and tables. Shopify is a well-known company that runs this way. It is a real architecture, not a failure.
Modules help the code, but all teams still share one release, one database and one runtime. As FTGO keeps hiring, the real limit becomes delivery contention: developers and teams getting in each other's way. One crash still stops everything, and one hot module still forces FTGO to copy the whole app. That is the pain that pushes teams toward separate services.
Split by function: the microservice architecture
If modules are not enough, FTGO has to change how the application runs, not only how its code is arranged. There are three ways to scale an application, and only one of them changes its structure.
FTGO already runs five copies of the monolith behind a load balancer. That handles more lunch-time orders, but every copy still contains all the code, the build is just as slow, and every team still waits for the same release. More copies do not make the code smaller.
The X axis clones the whole app behind a load balancer. The Z axis also runs copies, but routes each request by a key (for example the customer's name), so each copy owns part of the data. Both help with load. Neither makes the code easier to change.
Split the application by business function into small services. Each service has one focused job, owns its own data, and talks to the others only through its API. An API gateway gives web and mobile clients a single front door.
In practice a microservice is a small, independent process with its own deployment schedule. One owner, a person or a team, builds, tests, deploys and runs it. On its own it does little. A microservices application is many of them, usually running in a cluster managed by an orchestrator such as Kubernetes, working together over the network. In the hands-on chapter 26 you build one with Docker, Docker Compose and Kubernetes.
What makes this work is not size. Three ideas hold it together, and one of them is the one to protect: independent deployability. You can change a service, deploy it and release it to users without touching any other service, and you do it that way by habit.
To deploy alone, a service must be loosely coupled to the others, with a stable, explicit contract. That is why services are shaped around a business domain, and why each one hides its data, the same idea as encapsulation in object-oriented code. Sharing a database is one of the worst things you can do to independent deployability.
Splitting the code is only half the change. If FTGO cuts services but keeps its teams organized as before, every feature still needs several teams to agree, and the services drift back into one release: a distributed monolith.
Slices, not layers: one team per service
Services follow business functions, so the teams that build them should too.
FTGO wants to let customers save a favorite cuisine. Today FTGO has a web UI team, a backend team and a database team, so this tiny feature needs three teams, three backlogs and a fixed deploy order: database first, then backend, then UI.
Group code by business function, not by technology. Each service is a vertical slice with its own UI part, logic and data, and one small team owns it from idea to production. Such a team is called a stream-aligned team.
A slice is not enough on its own either. Fast, safe delivery needs three things at once: the architecture, a DevOps process with continuous integration and delivery, and small teams that own their services. Conway's law says a system's structure mirrors the communication structure of the organization that builds it, so FTGO must shape its teams as deliberately as its services. Chapter 25 returns to this.
Each team now builds and runs its own service, so it needs operations skills it never needed before. And some FTGO architects have seen "services" before: years ago the company tried a service-oriented architecture, and it did not end well. Why should this time be different?
Not SOA again: dumb pipes and private data
Microservices are often dismissed as "SOA with a new name". The difference is in where the logic and the data live.
FTGO's earlier SOA effort put an enterprise service bus between all systems. Over time the bus gathered routing rules, data transformations and then business rules. All services read one shared global database. In the end, every change needed the bus team, and the bus became a monolith of its own.
Keep all business logic inside the services, organized around business domains, and keep the connections between them simple: plain REST or gRPC calls, or a message broker that only moves messages. Each service keeps its data private.
There are two common ways for services to work together. They can call each other directly, or they can publish events ("order placed") to a broker and let any interested service react. In the event-driven style, a new consumer plugs in without the producer changing at all.
Most real systems mix both styles; purely event-driven systems are rare outside books and proofs of concept. Events also change how data is shared: instead of one service pulling a large data set through another's API, a consumer reads the event stream and builds its own local copy. Chapters 4 and 5 cover both styles in depth.
Dumb pipes push the hard work into the services and their teams: contracts, versioning and failure handling. Before FTGO pays that price, it should know exactly what it gets back.
What FTGO gains
Every benefit of microservices comes from the same source: small, separate parts that deploy independently and, where events are used, are decoupled by a durable broker. Here is what that means for each pain from the first section.
| Benefit | How it works for FTGO |
|---|---|
| Independent deployment | The delivery-time fix ships alone, today. Releases stay small and a rollback is quick. Each team owns the full life cycle of its service. |
| Team autonomy | Teams agree on an API or event contract, then build in parallel without merge conflicts. |
| Tunable scaling | Order Service gets ten instances at lunch, reporting keeps one. Each service scales its own database too. |
| Technology choice | The right store for each job, for example a search engine for restaurant search and a relational database for payments. A new language can be tried on one small service at low risk. |
| Robustness | A memory leak in Notification Service crashes only that service. Service boundaries act like bulkheads in a ship, but only if you design for network and machine failures. |
| Composability | Capabilities become addressable seams that the website, the mobile app and partners can combine in new ways. |
| Evolving architecture | Add a consumer without touching the producer, retire a service without breaking others, or replace a messy service with a new one. |
| The past on demand | A new service replays the history of events to build its data instead of running a special migration. |
Robustness depends on how services talk. Take a chain of synchronous calls: if the last service is down, every caller fails with it. With events, the downstream service keeps a local copy of what it needs and keeps working.
The past on demand works because a log-based broker keeps the events. Say FTGO adds a service that needs every restaurant. Copying them through an API means slow, throttled paging while tracking changes made during the copy. Replaying the event stream from offset 0 avoids both: when the new service reaches the newest event, every change in between is already applied.
Companies have grown this way. Gilt started in 2007 as one Rails monolith, found it overloaded by 2009, and now runs more than 450 services. Freedom of technology has limits, though: Netflix and Twitter mostly stick to the JVM, because every extra stack is one more thing to support.
None of these gains is free. Each one is paid for in distributed-system complexity, and the bill arrives on the first day, long before the benefits.
What FTGO pays
Microservices are not a silver bullet. They buy speed and independence and charge for it in complexity.
Three months after the first split, an FTGO developer cannot run the order flow on a laptop, because it now spans six services owned by four teams. A bug that used to be one stack trace is now spread over the logs of five processes. Placing an order makes network calls that used to be method calls, so it got slower. And the monthly revenue report breaks, because its data now lives in several databases.
Many of these costs are things the monolith gave FTGO for free. This is what changes when they are gone:
| The monolith gave you | With microservices |
|---|---|
| A visible business flow | The flow is spread over calls and events between services. You must follow them to see the whole process. |
| No network, no versioning | A breaking change needs two API or event versions side by side, and coordination between teams. |
| Run it all locally | The workflow spans many services owned by other teams, each with its own setup. |
| Easy code reuse | Services duplicate some code on purpose to avoid coupling. Shared libraries only for plumbing such as logging. |
| One place to monitor | Dozens of processes need central logs, metrics and tracing from day one (chapter 17). |
| End-to-end tests of everything | Mostly impractical. Quality comes from other kinds of tests (chapter 15). |
| ACID transactions and in-memory locks | Eventual consistency across services (chapter 9), and locks that must work across instances. |
Expect these pain points, and plan for them:
Two attitudes help. First, treat adoption as a dial, not a switch: add services slowly and add tools such as Kubernetes only when a pain calls for them. Second, see the trade clearly. Microservices bring some pain forward, to a point where it is cheaper to handle, and they give hard boundaries that stop the code turning into spaghetti. But they demand higher technical skill, and distributed applications are hard.
With gains and costs on the table, the decision is still open: should FTGO split now, and if so, where should it start?
When to split, and where to start
You have not mastered a tool until you know when not to use it.
An FTGO architect proposes rewriting the whole platform as event-driven microservices "because that is how modern companies do it". The plan has no measurable goal, no central logging, no automated tests and no deployment pipeline. In a year, nobody will be able to say whether it worked.
The strongest reason to adopt microservices is to let more developers work on one system without getting in each other's way. A five-person startup will find them a drag. A fast-growing company with a hundred developers may find growth easier.
A new product is still discovering its domain, so its service boundaries would keep moving, and every move across services is expensive. Uber started with limousines and Flickr grew out of an online game. For a startup, the monolith is the sensible default. A minority view argues the opposite: complexity always arrives, so start with microservices and avoid a risky conversion later. Judge by your team size, how stable the domain is, and how much operations skill you have.
FTGO is not a startup any more. It has many teams and a well-understood domain, so it does have a case. The question is how to move without betting the company.
Name one clear reason for moving, such as release frequency or team size, and measure progress against it. If the monolith is a patchwork, first refactor it into a modular monolith; that may remove the pain on its own, and it reveals the boundaries. Then pick one domain to move first by weighing risk, value and viability.
"Pick a domain" hides the hardest question of all: where exactly do the service boundaries go? Get them wrong and FTGO builds the distributed monolith from the second section, with all the network pain and none of the independence.
A map of the problems ahead
Every cost in this chapter has known answers. They come as patterns: a pattern is a reusable answer to a common problem, together with its benefits and its drawbacks. Each pattern usually solves one problem and creates the next, and that chain is the structure of this course.
The costs from this chapter map onto that route. Each challenge below has its own chapter:
A few more topics appear along the way: orchestration versus choreography in chapter 9, event sourcing in chapter 10, CQRS in chapter 11, and the broker toolbox (topics, partitions, consumer groups, delivery guarantees) in chapters 5 and 6.
Patterns in this chapter
| Pattern | Problem it solves | What it costs |
|---|---|---|
| Monolithic architecture | A small team needs to build, test and ship a new product fast | Grows into slow builds, rare releases, whole-app scaling, one-crash-kills-all and a stuck tech stack |
| Modular monolith | Tangled code inside one deployable (a big ball of mud) | Still one release, one database and one runtime; delivery contention as teams grow |
| X- and Z-axis scaling | More load than one copy of the app can handle | Every copy still holds all the code; complexity is unchanged |
| Microservice architecture (Y-axis split) | One codebase that every team must change and release together | Distributed-system complexity: network calls, partial failure, data spread over services |
| Stream-aligned teams owning slices | Small features that need hand-offs between layer teams | Each team needs operations skills; teams and services must be shaped together |
| Smart endpoints, dumb pipes | An enterprise bus that collects business logic and becomes a monolith | Contracts, versioning and failure handling move into every service |
| Event-driven communication | Callers that fail when a downstream service fails; new consumers that need old data | A broker to run; flows are harder to follow; data is eventually consistent |
| Incremental, measured migration | Big-bang rewrites with no clear goal | Needs a measurable reason, a modular first step and prerequisites such as CI/CD and central logging |
Recap
- A monolith is simple while small, but as FTGO grew it brought slow builds, rare releases, whole-app scaling, a single point of failure and a stuck technology stack.
- A monolith is defined by what you deploy together: a modular monolith is a valid architecture, while a distributed monolith has the costs of both worlds and the benefits of neither.
- The microservice architecture splits an application by business function into services that own their data, and its key property to protect is independent deployability.
- Services work best as end-to-end slices owned by small teams with a DevOps process, and they keep the logic in the services and the pipes dumb, unlike older SOA.
- Microservices give independent deployment, team autonomy, targeted scaling and contained failures, but cost a lot in testing, monitoring, data consistency, latency and operations.
- Move only for a clear, measured reason, turn the dial up slowly, and start from a modular monolith with the domain that best balances risk, value and viability.
Quick check
Show answer
Early on it does not have the problems microservices solve. A distributed system slows down fast iteration, and the domain is still changing, so service boundaries drawn now would have to move later at great cost. Learn the domain first.
Show answer
No. This is a distributed monolith: it keeps the lockstep release and the shared-data coupling of the monolith and adds network calls and partial failure on top. Each service must own its data behind an API and be deployable on its own; otherwise a modular monolith would serve FTGO better.
Show answer
Which specific problem are we solving, and could a modular monolith solve it? Pick a measurable reason, such as team size, database scaling or release frequency, track it during the move, and check that the prerequisites (deployment pipeline, central logging and monitoring, automated tests) are in place.
FTGO has decided to split, one domain at a time. But splitting only helps if the boundaries are right: where should the line between Order, Kitchen and Delivery go, and what happens to the classes that every part of the monolith uses?
Monolith vs microservices: common questions
When should you move from a monolith to microservices?
When teams block each other on deploys, parts need to scale or release independently, and you can afford the operational cost. A small team is usually faster with a modular monolith.