|$ curl https://forge-ai.dev/api/markdown?path=docs/architecture/microservices
$cat docs/microservices-architecture.md
updated Today·22-30 min read·published

Microservices Architecture

ArchitectureMicroservicesAdvanced🎯Free Tools
Introduction

Microservices architecture structures a system as independently deployable services aligned to business capabilities (bounded contexts), each owning its data and communicating via explicit contracts. This page focuses on the software architecture choice and requirements drivers — when to adopt, how to decompose, and when not to. For runtime patterns (discovery, resilience, scaling), see System Design → Microservices.

warning

If you cannot name the requirements that force independent deployability, start with a modular monolith.
Requirements That Justify Microservices
DriverWhy services helpCost you accept
Multiple teams need autonomous releaseReduce release couplingCross-service versioning
Different scale/SLO per domainIndependent scaling & isolationOps complexity
Polyglot or specialized runtimesChoose fit per serviceFragmented skills
Hard blast-radius isolationFault isolation by processPartial failure modes
Regulatory data boundariesSeparate trust domainsGateway & audit overhead
When NOT to Use Microservices
  • Team smaller than roughly two pizza teams with unclear domain boundaries.
  • Domain still learning — boundaries will move weekly.
  • You lack CI/CD, observability, and on-call maturity.
  • Primary pain is messy code — distribution will not heal coupling.
  • You need frequent cross-entity ACID transactions without a plan.

danger

A distributed monolith — many services sharing one DB or calling each other in tight sync chains — combines the worst of both worlds.
Decomposition: Bounded Contexts

Use domain-driven design heuristics: linguistic boundaries, data ownership, change frequency, and team ownership. Prefer splitting along seams you already modularized in a monolith.

Capability first

Billing, Identity, Catalog — not "ControllerService" or "UtilsService".

Data ownership

Each service owns its store; others use APIs/events — no shared tables.

Contract design

Versioned APIs; consumer-driven contracts where multiple consumers exist.

Transaction reality

Replace distributed ACID with sagas/outbox and explicit consistency models.

Communication Choices
StyleUse whenWatch out
Sync request/responseNeed immediate answer; simple queriesCascading latency/failures
Async events/messagesDecouple; fan-out; temporal independenceEventual consistency
Async commandsAsk another service to do workOwnership of retries/idempotency

Prefer choreography or orchestration deliberately. Document consistency expectations in NFRs and user-visible UX (e.g., "payment pending").

Data Ownership & Consistency
  • No shared writable database across services.
  • Publish domain events for state changes others must know.
  • Use outbox/inbox patterns for reliable publishing.
  • Accept eventual consistency where requirements allow; reserve strong consistency for narrow local aggregates.
outbox-sketch.txt
TEXT
1In one DB transaction:
2 1) Update order status = Paid
3 2) Insert outbox row OrderPaid
4Async publisher relays outbox → broker
5Consumers update their own projections idempotently
Team Topology Link

Microservices work best when team boundaries match service boundaries (Conway's Law as a tool). Stream-aligned teams own services end-to-end; platform teams provide paved roads; enabling teams coach. Misalignment — many teams editing one service, or one team owning twenty — recreates coupling.

Topology smellArchitectural response
Many teams in one serviceSplit along team seams OR merge teams
One team, 30 microservicesConsolidate into fewer deployables
Ticket ping-pong for featuresWrong boundaries; redesign ownership
How to Adopt Safely
  • Modularize the monolith first; extract along proven seams.
  • Establish platform baselines: CI templates, auth, observability, deployment.
  • Start with one extraction that has a clear driver (scale or team).
  • Invest in contract tests and progressive delivery before wide rollout.
  • Track distributed tracing from day one of the first split.
Microservices Decision Checklist
microservices-checklist.txt
TEXT
1[ ] Drivers written (team/scale/SLO/compliance)
2[ ] Bounded contexts identified with data ownership
3[ ] Consistency model agreed with product for UX
4[ ] Platform maturity sufficient (CI/CD, obs, on-call)
5[ ] Modular monolith alternative considered
6[ ] First extraction plan is incremental (strangler)
7[ ] ADR approved with consequences
Anti-Patterns
  • Nano-services: every class a network call.
  • Shared libraries that force lockstep deploys across all services.
  • Chatty sync call chains (A→B→C→D) without timeouts/bulkheads.
  • Entity services ("CustomerService" CRUD only) with no business cohesion.
  • Copying org chart poorly — accidental boundaries.
SDLC Implications

Microservices demand mature DevOps: independent pipelines, contract testing in CI, coordinated schema/event evolution, and clear ownership. Scrum-of-scrums or team-of-teams coordination focuses on contracts and shared goals — not centralized code approval for every change.

SDLC concernMicroservice practice
TestingUnit + contract + selective E2E
ReleaseIndependent deploy + compatible contracts
RequirementsNFRs per service + cross-journey SLOs
DesignADRs per service + platform standards
Example Decomposition
ecommerce-services.txt
TEXT
1Identity — accounts, sessions, roles
2Catalog — products, pricing read models
3Checkout — cart, order placement
4Payments — charges, refunds (PCI boundary)
5Fulfillment — shipping, inventory reservations
6Notify — email/push (consumes events)
7
8Sync: Checkout → Payments charge
9Async: OrderPlaced → Fulfillment, Notify, analytics
Cost Model (Honest)

Each service adds: pipeline, dashboards, alerts, on-call surface, versioning, local-dev complexity, and failure modes. Budget platform investment before proliferating services. A useful heuristic: do not have more services than you can staff with clear owners and SLOs.

Hidden costMitigation
Local environment painDev containers; narrow stubs; contracted fakes
Event versioning debtSchema registry; compatibility tests
Orphan servicesOwnership catalog; delete ruthlessly

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.