Chapter 01 of 27 · Part 1: Foundations

Escaping monolithic hell

Why a big single app becomes painful, when a monolith is still the right call, and what microservices give and take.

key idea / coordinatorservice / good pathin progress / watch outproblem / failureneutral

The story: FTGO

FTGO is a food-delivery company. It built everything as one program, a monolith: one codebase, one database, one deployable package. That is a good idea at the start.

A monolith and the pain it causesOne big app with six modules and one database, with six problems that appear as it grows.One big app (monolith)OrdersDeliveryPaymentsRestaurantsBillingNotificationsOne shared databaseAs it grows you get:Too complexSlow buildsRare releasesHard to scaleOne bug kills allStuck on old techFine when small.Painful when big.
FTGO is a food-delivery app. It started as one program.

Why splitting helps

There are three ways to scale an application. Only the Y axis changes the structure, by cutting the app into services.

The scale cube: three ways to scaleX clones copies, Z slices data, Y splits by function.X: clone itsame app, many copiesZ: slice the dataeach copy owns some usersY: split by functionthis is microservicesLoad balancerAppAppAppRouterA–HI–PQ–ZOrder serviceCustomer serviceReview service
X and Z help with load. Only Y fixes the complexity.

The microservice version

Each service has one focused job and talks to others only through its API. The API gateway is the single front door for mobile apps.

FTGO as microservicesClients go through an API gateway to five services, each with a private database.ClientsAPI gatewaysingle front doorOrderown DBDeliveryown DBRestaurantown DBKitchenown DBAccountingown DB
Each service owns its data. Nobody reads another service's tables.

Three key ideas

From Building Microservices: three ideas explain what makes microservices work. The one to protect is independent deployability: you can change a service, deploy it and release it without touching any other service, and you do it that way by habit.

Three key ideas of a microserviceModeled around a business domain and owning its own state make independent deployability possible.Modeled on the domainbusiness-shaped boundariesOwns its own stateno shared databaseIndependent deploysship it without othersResult: change one service, deploy it alone, release it to usersSize 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 get there, services must be loosely coupled with stable, explicit contracts. That is why they are shaped around a business domain and why each one hides its own data. Sharing a database is one of the worst things you can do to independent deployability. Hiding the data is the same idea as encapsulation in object-oriented code.

Slices, not layers

A classic three-tier system groups code by technology, so even a tiny feature crosses three teams. Microservices group by business function instead. Each service is an end-to-end slice, and the team that owns it is what Team Topologies calls a stream-aligned team.

Layered teams versus an end-to-end sliceA small change like a favorite-genre field needs three teams in a layered design but one team in a slice.Layers: one change, three teamsWeb UI teamBackend teamDatabase teamHand-offs and a fixed deploy order.Slice: one team owns it allCustomer profile teamUI for this featureBusiness logicIts own dataOne team ships the whole change.
Example from the book: letting a customer pick a favorite music genre.

A microservice in practice

Bootstrapping Microservices defines a microservice as a small, independent process that runs on its own deployment schedule and can be updated alone. One owner (a person or team) is responsible for building, testing, deploying and running it. Alone it does little. A microservices application is many of them, usually in a cluster, working together over the network.

A microservices application in practiceUsers reach a gateway service inside a cluster. Small services each do one job, and some use a database or file storage.UsersCluster managed by an orchestrator (Kubernetes)Gateway serviceVideo streamingHistoryVideo storageDatabase serverFile storage
Based on the video-streaming example in Bootstrapping Microservices.

Some services face the outside world, such as the gateway. Others are purely internal. Each usually has its own database or file storage. The same tools appear again and again in that book: Docker to package a service, Docker Compose to try the whole app on a laptop, Kubernetes to host it, and Terraform and GitHub Actions to build the cloud setup.

Three kinds of monolith

Building Microservices calls a system a monolith when everything must be deployed together. That covers three common shapes, and only one of them is bad.

Three kinds of monolithSingle-process, modular and distributed monoliths compared. The distributed one is the worst of both worlds.Single-processall code, one processOne processall the code togetherDatabaseModularmodules, one deploymentOrdersCatalogBillingSearchOne databaseoften not splitDistributedmany services, one releaseService AService BService CDeployed togetherThe 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, simple deploymentThe database is rarely split like the code
DistributedFew: it is a distributed system plus a monolithTight coupling and no information hiding

The modular monolith (Shopify is the book's example) is a real choice, not a failure. Delivery contention, meaning developers and teams getting in each other's way, is the pain that pushes people toward service boundaries.

Monoliths are not all bad

Rocha starts by defending the monolith. A well-structured one is a valid architecture, and a distributed system takes away several things you used to get for free. From Practical Event-Driven Microservices Architecture, ch. 1.

Patchwork versus modular monolithBoth are one deployable. The patchwork has tangled dependencies, the modular one has explicit boundaries.Patchwork monolith (big ball of mud)OrdersInventoryCheckoutReportsModular monolithOrdersInventoryCheckoutReportsStill one deployable unit in both cases. Only the visibility of the dependencies differs.

Things a single codebase gives you, and what happens to each when you go event-driven:

Monolith propertyWhat changes with event-driven microservices
Business flow is visibleThe flow is spread over events between services. You must follow the events to see the whole process.
No network, no versioningA breaking change needs two 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 code on purpose to avoid coupling. Shared frameworks only for plumbing such as logging.
One place to monitorDozens of services need central logs, metrics and tracing from day one.
End-to-end tests are possibleMostly not practical any more. Quality comes from other practices (lesson 15).
ACID and in-memory locksEventual consistency, and locks that must work across instances (lesson 06).

When the monolith becomes a constrictor knot

The more the business pulls (more users, more data, more developers), the tighter a patchwork monolith pulls back. The book names five pains and says to pick one clear reason before migrating, then measure progress against it. From Practical Event-Driven Microservices Architecture, ch. 1.

PainWhy a monolith strugglesWhat event-driven microservices offer
CouplingBoundaries fade. A change to subscriptions can break login.Services are decoupled by design through events.
Team autonomyMerge conflicts, coordinated releases, hard to scale the team.Teams own sets of services and agree only on contracts.
Release cycleEvery release validates and deploys everything.Small independent deployments.
ScalingScale the whole app. The database scales vertically.Scale one service; each owns its data.
Old stackUnsupported technology, hard to replace as a whole.Replace one service at a time; mixed stacks allowed.
Scaling the whole application versus one serviceA monolith is copied as a whole. Microservices scale only the busy service.Monolith: copy everythingAppordersreportsAppordersreportsAppordersreportsMicroservices: scale what is busyOrderOrderOrderReports (1 instance)Peak in orders? A monolith pays for reporting capacity it does not need. Microservices do not.

Moving is a decision, not a default. A startup still learning its domain should keep a monolith, because redrawing service boundaries later is costly. If the monolith is a patchwork, refactoring it into a modular monolith is the best first step. It may remove the original problem, and it reveals the boundaries.

Where to start a move to event-drivenMake the monolith modular, choose a domain by risk, value and viability, then decouple it with events.Modular firstmap the boundariesChoose a domainrisk, value, viabilityDecouple itservice reacts to eventsRisk = 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.
Weighing it: the book quotes Kelsey Hightower: you have not mastered a tool until you understand when not to use it. Event-driven microservices need pipeline automation, central logging and monitoring, automated tests and a broker before they pay off.

Gains and costs

Microservices are not a silver bullet. They buy speed and independence and charge you in distributed-system complexity.

Benefits and drawbacks of microservicesWhat you gainDeploy often and safelyScale each service aloneTeams work independentlyOne failure stays containedEasy to try new techWhat you payHard to choose the splitDistributed systems are complexFeatures span many teamsHard to know when to adoptTip: a startup should usually begin with a monolith.

The benefits, one by one

Each benefit in Building Microservices follows from small, separate, independently deployable parts.

Six benefits of microservicesTechnology choice, robustness, scaling, ease of deployment, organizational alignment and composability.Technology choiceright tool per serviceRobustnessboundaries act as bulkheadsScalingscale only the hot partEasy deploymentsmall, fast, safe releasesTeam alignmenta team owns a sliceComposabilitymany seams to reuseGilt: one Rails monolith in 2007, overloaded by 2009, now over 450 services.Netflix and Twitter mostly stick to the JVM: freedom has a cost.

The promise: seven benefits

Each benefit comes from the same mechanism: small services decoupled by a durable broker. From Practical Event-Driven Microservices Architecture, ch. 1.

BenefitHow it works
Evolving architectureAdd a consumer without touching the producer; retire services without breaking dependents; replace a messy service with a new one.
Independent deploymentChange the tax calculation in the pricing service and deploy only it. Ownership of the full life cycle moves to teams.
Team autonomyTeams agree on the event contract, then build in parallel.
Flexible stackA geo-distributed store for one service, another database elsewhere; mixed languages.
ResilienceFaults stay local; brokers absorb the load; instances can fail over.
Tunable scalingAdd consumer instances where lag grows; databases are distributed per service.
The past on demandNew consumers replay history instead of running a special migration.
A failure in a leaf service: chain versus eventsWith synchronous calls the failure cascades upstream. With events it stays local.Synchronous chainOrderfails tooPricingfails tooShippingfails tooLocationdownEvent-drivenLocationdownBrokerkeeps eventsShippinguses local copyOrderstill worksShipping only misses new location changes while Location is down. The order flow keeps running.
Migrating data by query versus by replaying a streamA query-based migration must handle changes during the copy. A stream replay catches up by reading to the end.Query basedSource APIthrottled pagingCopy jobmust track changesNew servicerisky corner casesStream basedEvent logfrom offset 0New servicereads to the endWhen the consumer reaches the newest event, every change in between is already applied.

More pain points

The earlier cost list is just the start. Building Microservices names these problems you should plan for. Most have a fix later in the course, such as sagas for data consistency, tracing for monitoring and contract tests for testing.

Nine pain points to expectDeveloper experience, technology overload, cost, reporting, monitoring, security, testing, latency and data consistency.Developer experiencecannot run 20 on a laptopTechnology overloadno Kubernetes for 3 servicesCostmore machines, slower at firstReportingdata split across schemasMonitoringwhich of 100 processes?Securitydata now crosses networksTestingend-to-end tests get hugeLatencyserialize and send, not callData consistencyno easy cross-service txnThink of a dial, not a switch: turn it up slowly and add tools when a pain appears.

Bootstrapping Microservices adds a mindset: microservices bring the pain forward to a point where it is cheaper to handle. They need higher technical skills, and distributed applications are hard, but they give hard boundaries that stop spaghetti code.

When to use them

Building Microservices says the biggest reason to adopt them is letting more developers work on one system without getting in each other's way. A five-person startup will find them a drag. A rapidly growing hundred-person company may find its growth easier.

When microservices fit and when they do notGood fits and poor fits, plus two views on monolith first versus microservices first.Works wellWorks poorlyMany developers, fewer collisionsSaaS: 24/7 uptime, release aloneCloud services fit each serviceMany channels reuse capabilitiesNew product, domain still movingTiny team: overhead hurtsSoftware customers installTwo viewsMonolith first (Newman)ask for a reason to splitMicroservices first (Bootstrapping)bring the pain forward

A new product is still changing its domain model, so service boundaries move and every move is expensive. Uber started with limos and Flickr grew out of a game. Newman treats the monolith as the sensible default. Bootstrapping Microservices argues the opposite: because complexity always arrives, 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.

Not the same as SOA

Older service-oriented architecture used heavy shared infrastructure. Microservices prefer simple connections and private data.

SOA compared with microservicesSOA (older)Smart pipes (heavy ESB, SOAP)One shared global databaseA few large servicesMicroservicesDumb pipes (REST, gRPC, broker)A database per serviceMany small services

SOA, microservices and event-driven

Event-driven is not "SOA again". SOA with an enterprise service bus organizes around reusable services and lets the bus orchestrate. Microservices and event-driven organize around domains and avoid sharing. In SOA the bus tends to collect business logic and becomes a monolith of its own. From Practical Event-Driven Microservices Architecture, ch. 1.

Three architectures for the same order flowSOA routes through a bus, microservices call each other, event-driven services react to events on a broker.SOA with a busMicroservicesEvent-drivenService busorchestrates and routesOrderPricingOrder svcInventoryPricingsync callsOrder svcEvent brokerInventoryPricingBus: logic drifts into it.Own DB per service.New consumers just plug in.

Most real systems mix both styles. Pure event-driven systems are mostly found in books and proofs of concept. Event streams also change how data is shared: instead of one service pulling a large data set through an API, consumers read the stream and build their own view.

It is not only architecture

Fast delivery needs three things at once: the architecture, a DevOps process, and small teams that own their services.

Architecture, process and organization togetherArchitecturemicroservices+ ProcessDevOps, CI/CD+ Organizationsmall teams= Resultfast, safe deliveryConway's law: software mirrors team structure, so shape the teams too.

A map for the rest of the course

The book describes its ideas as patterns grouped by the problem they solve.

Map of the pattern languageMicroservices patternsthe rest of the bookSplit upch 2Talkch 3Datach 4-6Queriesch 7APIch 8Testch 9-10Runch 11-13A pattern is a reusable answer to a common problem, with its benefits and drawbacks.

The challenges, and where this course covers them

What you give up is the other half of the story. Chapter 1 lists the challenges that the rest of the book answers. Each is a different lesson here. From Practical Event-Driven Microservices Architecture, ch. 1.

Challenges of event-driven architecturesEight challenges with the chapter and lesson that addresses each.Service sizech. 3 · lesson 02Stale readsch. 5 · lesson 09Concurrencych. 6 · lesson 06Resiliencech. 7 · lesson 18Event schemach. 8 · lesson 07UI designch. 9 · lesson 13Testingch. 10 · lesson 15Data fixesreverse commandNo shared database to patch: send the opposite command (RemoveStock after a wrong AddStock).
Where is ch. 4? Orchestration vs choreography, CQRS and event sourcing are covered in lessons 09, 10 and 11. The broker toolbox (topics, partitions, consumer groups, delivery guarantees) is in lessons 05 and 06, because the book teaches it in chapters 6 and 7.

Recap

Quick check

Why should a startup usually begin with a monolith?
Show answer

Early on you do not have the problems microservices solve. A distributed system slows down fast iteration, and the best way to find the right service boundaries is to learn the domain first.

Your team wants to move because "microservices are modern". What do you ask first?
Show answer

What specific problem are we solving, and could a modular monolith solve it? Choose a measurable reason such as team size, database scaling or release cycle, and track it during the move.