Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 20/ 31
Distributed Systems & Architecture

Microservices & Service Mesh

Decompose around domain boundaries while managing distributed transactions and service discovery.

IntermediateDomain Split · Sagas · Outbox3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Saga & Transactional Outbox Patterns

Keep multi-service workflows consistent without fragile Two-Phase Commit (2PC).

Advanced
Service Discovery & Service Mesh (Envoy/Istio)

How dynamic containers find each other and share mTLS, retries, and traces.

Intermediate

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

Loading interactive diagram
Loading interactive exercise

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.

Key takeaway: Start with a clean modular monolith; split out services only when team autonomy or independent scaling clearly justifies the network complexity.

How it works, step by step

Step 1 of 4
Service Boundaries

1. 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.

Database-per-service prevents tight schema coupling
Key numbers at this step
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

Modular Monolith
Best for: Small-to-medium teams, early startups, tight ACID workflows

Strengths: In-process function calls (nanoseconds), single ACID DB, simplest debugging.

Watch out: All modules share one deploy cadence and failure/memory boundary.

Saga Choreography (Events)
Best for: Simple 2–4 step decoupled flows (Order → Inventory → Email)

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.

Saga Orchestration (Temporal / Step Functions)
Best for: Complex multi-step workflows with timeouts, retries, and compensations

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?
Interview tip: Whenever a service updates a DB and publishes an event, always state “using the Transactional Outbox pattern” to eliminate dual-write drift.

Knowledge check

Loading quiz

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.

Open AI HLD Practice →SD Interview Q&A
Previous topic
API Design & Gateways
Next topic
Message Queues & Event Streaming