Monolith vs microservices

In one sentence

Start with a modular monolith; split out a service only when a team needs independent deploys or a part needs different scaling, because every split pays for autonomy with network hops and distributed data.

Analogy: One restaurant kitchen vs a food court: each food-court stall changes its menu and hours alone, but a combo meal now needs three counters, three queues and someone to reconcile the bill.

Keep CPU business logic in one modular deploy; extract the GPU inference path, which scales, deploys and fails differently.

How it works

  • A modular monolith keeps one deploy but enforces boundaries: modules never read each other's tables.
  • Each split turns a nanosecond call into a ~0.5 ms+ remote call that needs timeouts, retries and idempotency.
  • Data splits too: no cross-service JOINs or transactions, so you need sagas and eventual consistency.
  • Conway's law: draw service boundaries along team boundaries, or you get a distributed monolith that deploys together.
  • GPU inference is the textbook extraction: different hardware, scaling, deploy cadence and failure modes from the app tier.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your 25-engineer team runs a Django monolith. To add AI summaries, a 7B model now loads inside every web worker: every pod needs a GPU, deploys take 10+ minutes, and CUDA out-of-memory errors crash checkout requests. What do you do?

Go deeper

Full explanation

A monolith is one deployable unit: one codebase, one process type, usually one database. A modular monolith keeps the single deploy but enforces internal boundaries: modules with explicit interfaces that never read each other's tables. Microservices split those modules into separately deployed services that own their data and talk over the network (HTTP/gRPC or events).

What you buy:

  • Team autonomy: a team ships without a shared release train.
  • Independent deploys and fault isolation: a bad search deploy doesn't take down checkout.
  • Different scaling profiles: scale the hot or GPU-bound part alone.

What you pay:

Conway's law: systems mirror the communication structure of the org that builds them. Draw service boundaries along team boundaries, or you get a distributed monolith: services that must deploy together.

Fowler's MonolithFirst: boundaries are hard to guess before you understand the domain, so start modular and extract once the seams are proven.

AI angle: GPU inference is the textbook extraction. It differs from the CPU app tier in hardware, scaling, deploy cadence and failure modes.

Code Calling an extracted GPU inference service
pythonCalling an extracted GPU inference service
import asyncio
import httpx

# Before: summary = model.generate(text)  -- in-process, it could not time out.
# After: a network hop to a separately scaled GPU service (vLLM, OpenAI-compatible).
INFERENCE_URL = "http://inference.internal:8000/v1/chat/completions"
MODEL = "meta-llama/Llama-3.1-8B-Instruct"  # any model the GPU service serves

client = httpx.AsyncClient(timeout=httpx.Timeout(30.0, connect=1.0))

async def summarize(text: str) -> str | None:
    payload = {"model": MODEL, "max_tokens": 200,
               "messages": [{"role": "user", "content": f"Summarize: {text}"}]}
    for attempt in range(3):
        try:
            r = await client.post(INFERENCE_URL, json=payload)
            if r.status_code in (429, 503):       # GPU pool saturated: back off
                await asyncio.sleep(0.5 * 2 ** attempt)
                continue
            r.raise_for_status()
            return r.json()["choices"][0]["message"]["content"]
        except httpx.TransportError:               # timeouts, refused connections
            await asyncio.sleep(0.5 * 2 ** attempt)
    return None  # degrade: render the ticket without a summary
Real example

A 25-engineer SaaS runs a Django monolith. To add AI ticket summaries, they first load a 7B model inside the web workers: every web pod now needs a GPU, deploys take 10+ minutes to load weights, and a CUDA out-of-memory error crashes checkout requests too. They extract only inference into a vLLM service on an autoscaled GPU pool, called over HTTP with a 30 s timeout and a "summary unavailable" fallback. Web pods go back to cheap CPU nodes with 2-minute deploys; everything else stays in the monolith, now with enforced module boundaries.

Trade-offs +3 · −3

+ You gain

  • Teams deploy independently, without a shared release train.
  • Each service gets its own hardware and scaling: CPU web tier, GPU inference.
  • Smaller blast radius, as long as callers have timeouts and fallbacks.

− You pay

  • Every call becomes a network hop: added latency, timeouts and partial failure.
  • No cross-service transactions or JOINs: you need sagas, an outbox and eventual consistency.
  • An operational tax per service: pipelines, dashboards, on-call, version skew.

Use it when

Several teams blocking each other in one codebase, parts with clearly different scaling or hardware needs (GPU inference), or hard isolation boundaries, once the module seams are already proven.

Avoid it when

A single team, an early product whose domain boundaries still move, or when the reason is "it's modern" rather than a concrete deploy, scaling or ownership pain.

Numbers to know 3
  • Jeff Dean's latency numbers: ~100 ns for a main-memory reference vs ~500 µs for a round trip within a datacenter, thousands of times more.
  • Availability compounds: 5 sequential dependencies at 99.9% each give ~99.5% end to end (0.999^5).
  • Amazon's two-pizza rule: a service is owned by a team small enough to feed with two pizzas.
Common pitfalls 4
  • The distributed monolith: services that share one database or must deploy in lockstep. All the costs, none of the autonomy.
  • Splitting by technical layer (UI, logic, data service) instead of business capability, so every feature touches every service.
  • Chatty synchronous chains (A → B → C → D) that multiply latency and failure probability.
  • Splitting before you have per-service CI/CD, distributed tracing and clear on-call ownership.
Interview questions 3

Answer out loud first, then reveal.

Would you build a new AI product as microservices?Show answer

No. I'd start with a modular monolith: one deploy, but modules with explicit interfaces and no shared tables, enforced in CI. Boundaries are cheap to move inside one codebase and expensive across a network, and early on I don't know them yet; that's Fowler's MonolithFirst. The exception I'd make on day one is model inference: GPU serving has different hardware, scaling, deploy cadence and failure modes, so it lives behind its own API. I'd extract more only when a team or a scaling profile clearly demands it.

Your org has 40 microservices and every feature needs five teams to coordinate. What's wrong?Show answer

Conway's law is working against them: service boundaries don't match how work flows, so they've built a distributed monolith. I'd look for three signals: lockstep deploys, shared databases, and long synchronous call chains in traces. The fix is to redraw boundaries around business capabilities so one team can ship one feature, and to merge services that always change together. Fewer, larger services owned by stable teams usually beat many tiny ones. I'd also shape teams to the architecture I want, the inverse Conway maneuver.

How do you extract a service from a monolith safely?Show answer

With the strangler fig pattern. First I make the module a clean boundary inside the monolith: its own tables, reached only through an interface. Then I stand up the new service behind that same interface, route a slice of traffic to it through a proxy or feature flag, compare results and ramp up. Data moves last: the service becomes the owner, and everyone else reads through its API or its events, never its tables. Every step stays reversible until the old code is deleted.