Microservices & Infrastructure
Monolith vs modular monolith vs microservices, service boundaries with domain-driven design, synchronous vs asynchronous communication, API gateway and BFF, service discovery, service mesh and sidecars, containers and Kubernetes essentials, serverless, deployment strategies (blue-green, canary, feature flags), configuration, and data ownership.
Architectural styles
| Monolith | Microservices | |
|---|---|---|
| Deploy | one artifact | independent per service |
| Scaling | whole app | per service |
| Data | shared DB, ACID | DB per service, eventual consistency |
| Failure | one bug can take down all | isolation (if designed for it) |
| Latency | in-process calls | network hops |
| Debugging | stack traces | distributed tracing |
| Team fit | small teams | many autonomous teams |
Communication
| Style | Examples | Use when |
|---|---|---|
| Sync request/response | REST, gRPC | caller needs the answer now (queries, validations) |
| Async commands | queue (SQS, RabbitMQ) | work to be done by exactly one service |
| Async events | Kafka, SNS | broadcast facts; consumers decide what to do |
Avoid long synchronous chains (A → B → C → D): availabilities multiply (0.999⁴ ≈ 0.996) and latencies add. Prefer async events and local read models (CQRS) for data you need from other services.
The infrastructure around services
Service mesh vs library
| Concern | Library (Resilience4j, gRPC interceptors) | Mesh (Istio, Linkerd) |
|---|---|---|
| Languages | per language | any |
| Upgrades | redeploy every service | platform team upgrades proxies |
| mTLS | manual | automatic |
| Overhead | none extra | proxy hop, CPU/memory |
Containers and Kubernetes
Containers package an app with its dependencies, isolated via Linux namespaces (pid, net, mount, user) and limited via cgroups (CPU, memory) — see OS: processes. Images are layered and immutable.
apiVersion: apps/v1
kind: Deployment
metadata: { name: orders }
spec:
replicas: 3
strategy: { type: RollingUpdate, rollingUpdate: { maxUnavailable: 0, maxSurge: 1 } }
selector: { matchLabels: { app: orders } }
template:
metadata: { labels: { app: orders } }
spec:
containers:
- name: orders
image: registry.example.com/orders:1.42.0
ports: [{ containerPort: 8080 }]
resources:
requests: { cpu: "250m", memory: "256Mi" }
limits: { memory: "512Mi" }
readinessProbe: { httpGet: { path: /ready, port: 8080 }, periodSeconds: 5 }
livenessProbe: { httpGet: { path: /live, port: 8080 }, periodSeconds: 10 }
---
apiVersion: v1
kind: Service
metadata: { name: orders }
spec:
selector: { app: orders }
ports: [{ port: 80, targetPort: 8080 }]
Serverless
| Pros | Cons |
|---|---|
| no servers, scale to zero, pay per use | cold starts (ms–seconds) |
| automatic scaling | execution time and memory limits |
| great for event glue, spiky workloads | connection storms to databases (use proxies) |
| vendor lock-in, harder local testing |
Good for webhooks, image processing triggered by uploads, cron jobs, low-traffic APIs. Less good for latency-critical steady high traffic (containers are cheaper there).
Deployment strategies
Expand/contract migration for renaming a column: add new column → write both → backfill → read new → stop writing old → drop old. Each step is a separate deploy.
Twelve-factor essentials
Config in environment, stateless processes, backing services as attached resources, logs as event streams, disposability (fast start, graceful shutdown on SIGTERM — drain connections), dev/prod parity, one codebase per service.
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.