Scalable Web Architecture

Print this before the round. One card = one thing to recall under pressure.

Load Balancing Algorithms

AlgorithmUse whenGotcha
Round RobinStateless servers, uniform requestsFails with in-memory sessions
Least ConnectionLong-lived / variable-cost requests (SSR, uploads)Tracks state on LB
IP HashingMust reach same server (stateful WebSocket)Breaks if server dies; uneven distribution
Weighted RRMixed instance sizesManual weight tuning

Default: round robin + Redis session store. Stateless servers = freely distributable load.

Caching Layers (outer → inner)

1 — Browser cache

Hashed assets → max-age=31536000, immutable. HTML → no-cache (revalidate every time). Zero network cost on hit.

2 — CDN edge

Cloudflare — largest PoP, Workers for edge logic. CloudFront — AWS-native, Lambda@Edge. Akamai — enterprise SLAs, media. Purge on deploy.

3 — Redis (app cache)

Sub-millisecond reads. Supports TTL, pub/sub, sorted sets, persistence. Shared across all servers. Default over Memcached unless you need pure key-value + max simplicity.

4 — DB read replicas

Offload SELECT traffic from primary. Acceptable replication lag for read-heavy workloads.

Caching is a consistency contract. I always state the staleness budget before picking a strategy.

Redis vs Memcached

RedisMemcached
Data typesRich (lists, sets, sorted sets, hashes, streams)Strings only
PersistenceRDB + AOFNone
Pub/SubYesNo
ChooseDefault — almost alwaysSimplest possible KV cache only

Horizontal vs Vertical Scaling

Vertical (scale up)Horizontal (scale out)
HowBigger machine (CPU/RAM)More machines behind LB
LimitPhysical ceiling, SPOFEffectively unlimited
RequirementNothingStateless app servers
Default forDBs (until sharding needed)App servers — always

Make the app stateless first. Once sessions are in Redis, you can add servers freely — that's horizontal scaling unlocked.

Microservices

Benefits

  • Independent deploy per service
  • Independent scaling per service
  • Fault isolation
  • Tech heterogeneity

Hidden costs

  • Network latency + timeouts replace function calls
  • Distributed tracing required
  • No ACID across services (eventual consistency)
  • API versioning overhead

FE Lead's microservice concerns

  • BFF: aggregates multiple services → one request, UI-shaped response
  • Graceful degradation: show hotel card without pricing if pricing service is down
  • Contract: negotiate API versioning — no surprise breaking changes

Docker + Kubernetes (K8s)

Docker

Image = immutable snapshot (app + runtime + deps). Container = running instance. Registry = versioned image store (ECR, DockerHub). "Deploy" = pull image tag X and run it.

K8s conceptWhat it does
PodOne or more containers sharing a network namespace
DeploymentDesired replica count + rolling update strategy
ServiceStable virtual IP that routes to healthy pods
IngressHTTP router at cluster edge (hostname/path routing)
HPAHorizontal Pod Autoscaler — scale on CPU or custom metric
ConfigMap/SecretInject env vars without baking into image

Rolling deploy + readiness probes = zero-downtime. Rollback = kubectl rollout undo — K8s replaces pods with the previous image tag.

Terraform vs Docker vs K8s — three cadences

Terraform = provision the infra (VPC, the cluster itself, RDS, LB, DNS) — IaC, changes rarely. Docker = package the app into an immutable image — every commit. Kubernetes = run/scale/heal the images on Terraform's nodes — every deploy. Order: TF provisions cluster → Docker builds image → K8s rolls it out.

"Terraform builds the building, Docker is the standardized box, K8s is the dispatcher."

Interview answer structure — 10× traffic

  1. Edge: CDN for assets + cacheable APIs
  2. LB: L7 round-robin, health checks, auto-scaling
  3. App cache: Redis — session, hot data, TTLs per type
  4. Horizontal scaling: stateless servers, read replicas for DB
  5. BFF: aggregate microservices, one request per page
  6. Infra/containers: Terraform (provision, rarely) · Docker (package, per commit) · K8s Deployments + HPA (run, per deploy)

Don't fail the interview

Stateful servers + round robin = random cart wipes. Fix: move session to Redis → all servers are stateless → any algo works.

Cache invalidation is hard. Define your staleness budget first: "5-second stale data is OK" changes the entire strategy.

Don't start with microservices. Start monolith → identify seams → extract. Premature split multiplies ops burden before traffic justifies it ("microservices premium").

Don't self-host K8s. Use managed EKS/GKE. As Lead you need to own the concepts, not the cluster ops.

Terraform / Docker / K8s are not interchangeable. Dividing question = infra cadence or deploy cadence? Never terraform apply to ship an app version (wrong cadence, locks state); never kubectl your VPC. TF stops at the cluster → GitOps (ArgoCD/Flux) or Helm manages in-cluster app state.