Microservices & Service Mesh
Decompose around domain boundaries while managing distributed transactions and service discovery.
In plain words
Microservices split one big app into many small apps, each doing one job and owned by one team. A service mesh handles the networking between them: retries, security, and monitoring.
Think of it like…
A restaurant kitchen with specialized stations (grill, pastry, bar) connected by ticket rails, rather than one chef trying to cook 200 dishes at once.
Where you’ve seen it
Netflix runs separate services for login, recommendations, billing, and playback, so each team can ship changes without redeploying everything.
Words you’ll hear
- Monolith
- One single application containing all features.
- Microservice
- A small, independently deployable service with one responsibility.
- Service discovery
- How services find each other’s current addresses.
- Sidecar
- A helper proxy running next to each service (e.g. Envoy in Istio).
Visual diagram
Theory & deep dive
Modular Monolith first, Microservices when teams/scale demand it
Microservices solve organizational scaling (50 engineers deploying 10 features independently) and isolated scaling (video transcoding needs GPUs while billing needs compliance). They do NOT come free - they replace in-memory function calls with slower, failure-prone network calls.
Crucially, never share one database across microservices - otherwise two services remain tightly coupled and cannot deploy schemas independently.
How it works, step by step
Step 1 of 41. Start modular; split around clear bounded contexts
Each microservice owns its private database schema - never let Service B read Service A’s SQL tables directly.
- Rule
- Own your DB
- Anti-pattern
- Shared DB monolith
When to use it & trade-offs
What it is
Microservices split an application into independently deployable services organized by business domain, while a service mesh (Envoy/Istio) handles mTLS, discovery, retries, and telemetry at the network proxy layer.
Why it matters: Large teams step on each other in a giant monolith and need independent scaling/isolation, though splitting too early adds steep network and data-consistency overhead.
When to reach for it
- Isolating high-scale or high-risk domains (Payments, Video Transcoding, Auth)
- Transactional Outbox pattern whenever a DB mutation must also emit a Kafka event
- Sagas with compensating transactions (refund payment if shipping fails) instead of 2PC
When to avoid or be careful
- Building a “distributed monolith” where 10 services call each other synchronously in a deep chain
- Letting multiple services read/write the same SQL tables directly
Monolith vs. Choreography vs. Orchestration
Strengths: In-process function calls (nanoseconds), single ACID DB, simplest debugging.
Watch out: All modules share one deploy cadence and failure/memory boundary.
Strengths: No central coordinator SPOF; services stay loosely coupled via Kafka/events.
Watch out: Harder to trace end-to-end state and detect cyclic dependencies as steps grow.
Strengths: Explicit state machine visibility, durable timers, clean rollback logic.
Watch out: Adds an orchestrator component to operate and scale.
Interview signals & numbers to know
When this topic comes up
- cross-service transaction
- Saga
- outbox pattern
- service discovery
- mTLS
Benchmarks & rules of thumb
- In-process call vs RPC
- ~100 ns vs ~1 ms (10,000×)
- Sidecar proxy hop
- ~0.5–1.5 ms
- Cascading SLA (5 serial hops @ 99.9%)
- 0.999⁵ ≈ 99.5%
- Outbox poll/CDC lag
- <100 ms
Common mistakes & follow-ups
Common interview mistakes
- Performing a DB commit and then calling
kafka.send()directly (dual-write bug if the process crashes in between) - Chaining 8 synchronous microservice calls on the critical read path (compounds latency and drops availability)
- Using 2-Phase Commit (2PC) across external microservices, blocking locks during any network hiccup
Likely interviewer follow-ups
- How does the Transactional Outbox pattern solve the dual-write problem between PostgreSQL and Kafka?
- Why do 5 synchronous services each with 99.9% availability yield only ~99.5% combined availability?
- When would you choose Saga Orchestration (e.g., Temporal) over Choreography?
Knowledge check
Put it into practice
Design full architectures with AI feedback
Apply Microservices & Service Mesh inside real High-Level Design prompts or review Q&A flashcards.