Chapter 01 of 27 · Part 1: Foundations

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

Where we are

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.

This chapter

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

Problem

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.

A monolith and the pain it causes One big app with six modules and one database, with six problems that appear as it grows. One big app (monolith) Orders Delivery Payments Restaurants Billing Notifications One shared database As it grows you get: Too complex Slow builds Rare releases Hard to scale One bug kills all Stuck on old tech Fine when small. Painful when big.
FTGO started as one program. Each pain appears as it grows.

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:

PainWhat it looks like at FTGO
CouplingModule boundaries fade over the years. A change to restaurant menus breaks customer login.
Team autonomyMany developers in one codebase: merge conflicts, coordinated releases, and a team that is hard to grow.
Release cycleEvery release must validate and deploy everything, so even the delivery fix waits.
ScalingThe whole app is copied to scale one busy part, and the one database can only grow by buying a bigger machine.
Old stackThe technology is outdated, and replacing it means replacing everything at once.
Scaling the whole application versus one service A monolith is copied as a whole. Microservices scale only the busy service. Monolith: copy everything App orders reports App orders reports App orders reports Microservices: scale what is busy Order Order Order Reports (1 instance) Lunch peak? A monolith pays for reporting capacity it does not need. Microservices do not.
Cost

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.

Problem

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?

Three kinds of monolith Single-process, modular and distributed monoliths compared. The distributed one is the worst of both worlds. Single-process all code, one process One process all the code together Database Modular modules, one deployment Orders Menus Billing Search One database often not split Distributed many services, one release Service A Service B Service C Deployed together The distributed monolith keeps the network pain and the lockstep release.
A monolith is about what you deploy together, not about code quality.
KindGoodWatch out for
Single-processSimple to run, test and debugEveryone shares one codebase
ModularParallel work on separate modules, simple deploymentThe database is rarely split the way the code is
DistributedFew: it is a distributed system and a monolith at onceTight 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.

Patchwork versus modular monolith Both are one deployable. The patchwork has tangled dependencies, the modular one has explicit boundaries. Patchwork monolith (big ball of mud) Orders Inventory Checkout Reports Modular monolith Orders Inventory Checkout Reports Still one deployable unit in both cases. Only the visibility of the dependencies differs.
Solution · Modular monolith

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.

Cost

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.

Problem

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 scale cube: three ways to scale X clones copies, Z slices data, Y splits by function. X: clone it same app, many copies Z: slice the data each copy owns some users Y: split by function this is microservices Load balancer App App App Router A–H I–P Q–Z Order service Consumer service Restaurant service
X and Z help with load. Only Y fixes the complexity.

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.

Solution · Microservice architecture (Y-axis split)

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.

FTGO as microservices Clients go through an API gateway to five services, each with a private database. Clients API gateway single front door Order own DB Delivery own DB Restaurant own DB Kitchen own DB Accounting own DB
Each service owns its data. Nobody reads another service's tables.

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.

Three key ideas of a microservice Modeled around a business domain and owning its own state make independent deployability possible. Modeled on the domain business-shaped boundaries Owns its own state no shared database Independent deploys ship it without others Result: change one service, deploy it alone, release it to users Size matters least. Aim for a small interface, and a service one person can hold in their head.
Independent deployability is the idea to protect. The other two make it possible.

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.

Cost

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.

Problem

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.

Layered teams versus an end-to-end slice A small change like a favorite-cuisine field needs three teams in a layered design but one team in a slice. Layers: one change, three teams Web UI team Backend team Database team Hand-offs and a fixed deploy order. Slice: one team owns it all Consumer team UI for this feature Business logic Its own data One team ships the whole change.
Example: letting a customer pick a favorite cuisine.
Solution · End-to-end slices owned by stream-aligned teams

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.

Architecture, process and organization together Architecture microservices + Process DevOps, CI/CD + Organization small teams = Result fast, safe delivery Conway's law: software mirrors team structure, so shape the teams too.
Cost

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.

Problem

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.

Solution · Smart endpoints, dumb pipes

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.

Three architectures for the same order flow SOA routes through a bus, microservices call each other, event-driven services react to events on a broker. SOA with a bus Microservices Event-driven Service bus orchestrates and routes Order Kitchen Order svc Kitchen Delivery sync calls Order svc Event broker Kitchen Delivery Bus: logic drifts into it. Own DB per service. New consumers just plug in.

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.

Cost

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.

BenefitHow it works for FTGO
Independent deploymentThe 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 autonomyTeams agree on an API or event contract, then build in parallel without merge conflicts.
Tunable scalingOrder Service gets ten instances at lunch, reporting keeps one. Each service scales its own database too.
Technology choiceThe 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.
RobustnessA 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.
ComposabilityCapabilities become addressable seams that the website, the mobile app and partners can combine in new ways.
Evolving architectureAdd a consumer without touching the producer, retire a service without breaking others, or replace a messy service with a new one.
The past on demandA 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.

A failure in a leaf service: chain versus events With synchronous calls the failure cascades upstream. With events it stays local. Synchronous chain Order fails too Kitchen fails too Delivery fails too Location down Event-driven Location down Broker keeps events Delivery uses local copy Order still works Delivery only misses new courier locations while Location is down. Orders keep flowing.

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.

Cost

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.

Problem

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 youWith microservices
A visible business flowThe flow is spread over calls and events between services. You must follow them to see the whole process.
No network, no versioningA breaking change needs two API or event versions side by side, and coordination between teams.
Run it all locallyThe workflow spans many services owned by other teams, each with its own setup.
Easy code reuseServices duplicate some code on purpose to avoid coupling. Shared libraries only for plumbing such as logging.
One place to monitorDozens of processes need central logs, metrics and tracing from day one (chapter 17).
End-to-end tests of everythingMostly impractical. Quality comes from other kinds of tests (chapter 15).
ACID transactions and in-memory locksEventual consistency across services (chapter 9), and locks that must work across instances.

Expect these pain points, and plan for them:

Nine pain points to expect Developer experience, technology overload, cost, reporting, monitoring, security, testing, latency and data consistency. Developer experience cannot run 20 on a laptop Technology overload no Kubernetes for 3 services Cost more machines, slower at first Reporting data split across schemas Monitoring which of 100 processes? Security data now crosses networks Testing end-to-end tests get huge Latency serialize and send, not call Data consistency no easy cross-service txn Think of a dial, not a switch: turn it up slowly and add tools when a pain appears.

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.

Cost

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.

Problem

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.

When microservices fit and when they do not Good fits and poor fits, plus two views on monolith first versus microservices first. Works well Works poorly Many developers, fewer collisions SaaS: 24/7 uptime, release alone Cloud services fit each service Many channels reuse capabilities New product, domain still moving Tiny team: overhead hurts Software customers install Two views Monolith first ask for a reason to split Microservices first bring the pain forward

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.

Solution · Move for a measured reason, one domain at a time

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.

Where to start a move to microservices Make the monolith modular, choose a domain by risk, value and viability, then decouple it with events. Modular first map the boundaries Choose a domain risk, value, viability Decouple it service reacts to events Risk = how critical it is. Value = benefit of moving it. Viability = how practical the move is. A one-shot rewrite or a greenfield event-driven system is rarely the right call.
Prerequisites first. Microservices only pay off once you have an automated deployment pipeline, central logging and monitoring, automated tests, and (for event-driven services) a message broker. Without them, each new service adds pain and no speed. Chapter 23 shows how to move a live monolith step by step.
Cost

"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.

Map of the pattern language Microservices patterns the rest of the course Split up ch 2-3 Talk ch 4-7 Data ch 8-10 Queries ch 11 API, UI ch 12-13 Test ch 14-15 Run ch 16-25 A pattern is a reusable answer to a common problem, with its benefits and drawbacks.

The costs from this chapter map onto that route. Each challenge below has its own chapter:

Challenges of microservices and where the course covers them Seven challenges with the chapter that addresses each, plus how to fix bad data without a shared database. Service size chapter 2 Stale reads chapter 9 Concurrency chapter 6 Resilience chapter 18 Event schema chapter 7 UI design chapter 13 Testing chapter 15 Data fixes reverse command No shared database to patch: send the opposite command (RemoveStock after a wrong AddStock).

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.

Try it: the interactive pattern map lets you fix FTGO one pattern at a time and shows the new problem each pattern creates.

Patterns in this chapter

PatternProblem it solvesWhat it costs
Monolithic architectureA small team needs to build, test and ship a new product fastGrows into slow builds, rare releases, whole-app scaling, one-crash-kills-all and a stuck tech stack
Modular monolithTangled 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 scalingMore load than one copy of the app can handleEvery copy still holds all the code; complexity is unchanged
Microservice architecture (Y-axis split)One codebase that every team must change and release togetherDistributed-system complexity: network calls, partial failure, data spread over services
Stream-aligned teams owning slicesSmall features that need hand-offs between layer teamsEach team needs operations skills; teams and services must be shaped together
Smart endpoints, dumb pipesAn enterprise bus that collects business logic and becomes a monolithContracts, versioning and failure handling move into every service
Event-driven communicationCallers that fail when a downstream service fails; new consumers that need old dataA broker to run; flows are harder to follow; data is eventually consistent
Incremental, measured migrationBig-bang rewrites with no clear goalNeeds a measurable reason, a modular first step and prerequisites such as CI/CD and central logging

Recap

Quick check

Why should a startup usually begin with a monolith?
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.

FTGO splits its monolith into six services, but they all still read and write the same database, and every release ships all six together. Have they escaped monolithic hell?
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.

Your team wants to move because "microservices are modern". What do you ask first?
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.

Still open

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?

Next: 02 Decomposition strategies: where to cut →

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.