Monolith vs Microservices

System Design · Distributed Systems · Intermediate · 13 min

One big app or many small ones? Trade-offs every architect argues about.

One big kitchen becomes a food court. Each stall cooks on its own, but a single order now walks from counter to counter, and the customer waits for the whole walk: every stall's cooking time plus every stall it has to visit after.

The idea in everyday words

A monolith is a food truck: one kitchen does everything. It is simple and cheap, but if the fryer breaks, the whole truck stops. Microservices are a food court: separate stalls for pizza, sushi, drinks. Each can grow or fail on its own, but now you need a shared seating plan, signs and cleaners (networking, monitoring, deployment).

Trade-offs

Monolith Microservices
Start-up speed Fast Slow
Deploy All at once Each service independently
Scaling Whole app Only the hot service
Failure Can take down everything Isolated (if designed well)
Complexity Low High: network calls, tracing, data consistency

Rule of thumb: start with a well-organised monolith; split out services when a team or a hot path needs it.

Glue you'll need

  • API gateway (auth, routing, rate limits): AWS API Gateway, Kong, Apigee, Azure APIM
  • Service discovery and containers: ECS with Service Connect / Cloud Map, or Kubernetes (EKS / GKE / AKS)
  • Async events: SQS/SNS, EventBridge, Kafka (MSK), Pub/Sub
  • Observability: logs, metrics, distributed tracing (CloudWatch, X-Ray, OpenTelemetry)
  • Data: each service owns its DB; cross-service flows use sagas instead of one big transaction.

Feel the network cost

in_process_call_ms = 0.001
network_call_ms = 2
calls_per_request = 6

print("monolith:", calls_per_request * in_process_call_ms, "ms")
print("microservices:", calls_per_request * network_call_ms, "ms (+ retries, timeouts)")

Step by step

  1. Request:

    App → API gateway (auth + rate limit)

  2. Route:

    gateway → order-service

  3. Call:

    order-service → payment-service (gRPC)

  4. Event:

    publishes OrderPlaced → email & analytics services react

Code example

services = {"gateway": ["orders"], "orders": ["payments", "inventory"], "payments": [], "inventory": []}
def calls(svc, depth=0):
    print("  " * depth + svc)
    for dep in services[svc]:
        calls(dep, depth + 1)
calls("gateway")

Interview tips

  • Show maturity: 'I'd start with a modular monolith.'

  • Mention the saga pattern for distributed transactions.

  • Talk about observability: tracing across services.

Challenge: Request Latency Through Services

deps maps a service to the services it calls one after another (sequentially), latency maps each service to its own work in ms. Return the total latency of calling root (its own time + all downstream calls, recursively).

Example: total_latency({"api": ["db"], "db": []}, {"api": 5, "db": 20}, "api") → 25

Solve it in the browser with tests, hints and an AI coach.

Practice problems

More in Distributed Systems

Previous: Replication, Failover & Sharding · Next: Message Queues & Rate Limiting