system-design · intermediate

Microservices Architecture — Independently Deployable Pieces

Start here

Microservices architecture structures a product as many small(ish) services that:

You should care because “microservices” is both a powerful organizational tool and a fashionable way to create distributed failure. The right question is not “are microservices modern?” but “do our team and scale problems justify the tax?”

What you will learn

  1. Define microservices vs modular monolith.
  2. See benefits: autonomy, selective scale, isolation.
  3. See costs: latency, consistency, ops, debugging.
  4. Work a complete commerce split example.
  5. Apply rules of thumb for service boundaries.
  6. Avoid distributed monolith anti-patterns.

What you should know first

TopicWhy
Client–serverServices are servers to each other
API gatewayEdge entry
Sync vs asyncInteraction styles

Words you need before we begin

TermPlain English
ServiceIndependently deployable process with a clear API.
Bounded contextDomain modeling boundary for ownership.
Distributed monolithMany services that must deploy together and share databases.
SagaCross-service workflow with compensations.
ContractAPI/event agreement between services.
Fan-outOne request triggers many downstream calls.

Simple story: food court vs one mega-kitchen

A food court (microservices) has specialized stalls with their own inventory. A single mega-kitchen (monolith) shares one freezer and schedule. Stalls scale sushi independently, but getting a full meal may mean multiple queues and more walking (network hops).

The problem microservices try to solve

If you have five engineers and moderate traffic, a modular monolith often wins.

Step-by-step: adopting thoughtfully

Step 1 — Start with modular monolith boundaries

Packages/modules with clear APIs even inside one deployable.

Step 2 — Identify split candidates

Different scale, different compliance, different team ownership, frequent independent change.

Step 3 — Define contracts first

Versioned APIs/events; consumer-driven tests.

Step 4 — Separate data

No shared write DB across services. Integrate via APIs/events.

Step 5 — Provide platform basics

Discovery, gateway, observability, CI/CD, on-call.

Step 6 — Choose sync vs async per use case

User-facing authorize vs async email.

Step 7 — Measure the tax

Track deploy frequency gains vs incident complexity.

Visual mental model

flowchart LR
  GW[API gateway] --> Cat[Catalog service]
  GW --> Cart[Cart service]
  GW --> Ord[Order service]
  Ord --> Pay[Payment service]
  Ord -->|events| Mail[Email service]
  Cat --> CatDB[(Cat DB)]
  Ord --> OrdDB[(Ord DB)]

Learning question: Why is a shared company_db for all services a red flag?

Caption: It couples deploys and schemas—distributed monolith territory.

Complete worked example: commerce split

Starting situation

Monolith slows releases; catalog team blocked by checkout freezes.

Decisions

ServiceOwnsTalks via
CatalogProductsSync read APIs
CartCart contentsSync
OrdersOrder lifecycleSync create; events after
PaymentsChargesSync with idempotency
NotifyEmail/SMSEvents

Failure design

Payments timeout → fail order create carefully; never double charge (idempotency keys). Email down → order still succeeds.

Outcome

Catalog deploys thrice daily. Cost: need gateway, tracing, contract tests, more dashboards.

How it works in production

Failure modes

ModeImpactMitigation
Chatty sync meshesLatency & cascadesDesign coarser APIs; async
Shared DBCouplingSplit data ownership
No distributed tracingUn-debuggableTrace every hop
Too many services too soonOps collapseFewer, larger services
Distributed monolith deploysLockstep releasesTrue independence tests
Unowned servicesPager voidsClear ownership

Trade-offs

BenefitCost
Team autonomyCoordination overhead
Selective scalingDuplicated cross-cutting concerns
Tech flexibilityFragmentation risk
Fault isolation potentialPartial failure complexity

Compare with related concepts

ConceptDifference
Modular monolithOne deployable, strong modules
SOA (historic)Related ideas; often heavier ESBs
Functions/serverlessFine-grained deploy; different ops
EDACommunication style often used with microservices

Common misunderstandings

  1. “Microservice = small file count.” Size is about independence, not LOC pride.
  2. “Network is reliable.” Design for partial failure.
  3. “One DB is fine if schemas differ.” Still coupling.
  4. “We will find boundaries later.” Wrong splits are expensive—iterate carefully.
  5. “Kubernetes means we have microservices.” Platform ≠ architecture.

Check your understanding

  1. Name three benefits and three costs.
  2. What is a distributed monolith?
  3. Why own data per service?
  4. When keep a monolith?
  5. How do events help side effects?

Practice

  1. Propose three services for a ride-sharing app and their data.
  2. Identify a bad split (e.g., splitting by technical layer only).
  3. Design failure behavior when payments is down.
  4. List minimum platform capabilities before splitting.
  5. Critique a diagram with 40 services for a 6-person team.

Deeper production notes

Team topology

If you cannot staff on-call for a service, do not create it. Ownership is the scarce resource.

Contract testing

Without consumer-driven tests, independent deploys become production roulette.

Strangler pattern

Extract gradually from a monolith rather than big-bang rewrites.

Additional teaching scenarios

Scenario A — peak load day

Traffic multiplies by ten. Mark which failure modes appear first and the first mitigation for each.

Scenario B — mixed versions

Half the fleet runs an old build. Which assumptions break? Prefer one deploy window of compatibility.

Scenario C — five-sentence teach-back

Explain the core idea without acronyms.

Scenario D — metrics and alerts

List three metrics and one alert tied to user impact or scarce resources.

Scenario E — non-goals

Name two problems this technique should not solve.

Scenario F — ownership

Who owns dashboards, code, and pages?

Revision summary

Glossary

TermDefinition
MicroserviceIndependently deployable service with clear ownership.
Distributed monolithServices coupled in practice.
Bounded contextDomain boundary guiding splits.

Abbreviations and terminology

What to learn next

  1. Split a monolith safely
  2. Service discovery
  3. Event-driven architecture
  4. Outbox and sagas

Extra teaching notes for first-time builders

Write the single bottleneck you are protecting before picking tools. Name the signal that tells you the design is working for users, not only that internal counters move. When reviewing a change related to this lesson, ask what happens when the component is slow for ten minutes, down entirely, or running twice. Prefer small explicit failure modes that operators can understand at 3 a.m.

Document ownership for dashboards, code, and pages. Undocumented mechanisms become folklore and then outages. Prefer designs that tolerate mixed versions for at least one deploy window so rollouts do not require perfect global simultaneity.

Napkin math helps: estimate peak rate, multiply by payload size, and ask whether the design still holds when a dependency is at half capacity. If the answer depends on luck, add bounds, backpressure, or shedding before production traffic arrives.

Extra teaching notes for first-time builders

Write the single bottleneck you are protecting before picking tools. Name the signal that tells you the design is working for users, not only that internal counters move. When reviewing a change related to this lesson, ask what happens when the component is slow for ten minutes, down entirely, or running twice. Prefer small explicit failure modes that operators can understand at 3 a.m.

Document ownership for dashboards, code, and pages. Undocumented mechanisms become folklore and then outages. Prefer designs that tolerate mixed versions for at least one deploy window so rollouts do not require perfect global simultaneity.

Napkin math helps: estimate peak rate, multiply by payload size, and ask whether the design still holds when a dependency is at half capacity. If the answer depends on luck, add bounds, backpressure, or shedding before production traffic arrives.

Extra teaching notes for first-time builders

Write the single bottleneck you are protecting before picking tools. Name the signal that tells you the design is working for users, not only that internal counters move. When reviewing a change related to this lesson, ask what happens when the component is slow for ten minutes, down entirely, or running twice. Prefer small explicit failure modes that operators can understand at 3 a.m.

Document ownership for dashboards, code, and pages. Undocumented mechanisms become folklore and then outages. Prefer designs that tolerate mixed versions for at least one deploy window so rollouts do not require perfect global simultaneity.

Napkin math helps: estimate peak rate, multiply by payload size, and ask whether the design still holds when a dependency is at half capacity. If the answer depends on luck, add bounds, backpressure, or shedding before production traffic arrives.

Extra teaching notes for first-time builders

Write the single bottleneck you are protecting before picking tools. Name the signal that tells you the design is working for users, not only that internal counters move. When reviewing a change related to this lesson, ask what happens when the component is slow for ten minutes, down entirely, or running twice. Prefer small explicit failure modes that operators can understand at 3 a.m.

Document ownership for dashboards, code, and pages. Undocumented mechanisms become folklore and then outages. Prefer designs that tolerate mixed versions for at least one deploy window so rollouts do not require perfect global simultaneity.

Napkin math helps: estimate peak rate, multiply by payload size, and ask whether the design still holds when a dependency is at half capacity. If the answer depends on luck, add bounds, backpressure, or shedding before production traffic arrives.

FAQ from first-time learners

Q: How small should a service be?
A: Small enough for one team to own fully; large enough to avoid chatty networks.

Q: Is a modular monolith “legacy”?
A: No—it is often the correct default.

Q: Do microservices require Kubernetes?
A: No, but you need some mature deploy and discovery story.

Track: Software Design and Architecture

Previous: Fan-out on Write vs Fan-out on Read

Next: Notification System Design — Reference Architecture

By Shubham Jain

All articles · Study paths

Shubham Jain · Learning Lab