System Design blueprint · Tech & SaaS
Scalable web architecture
The classic path of a request, from DNS to replicated data, and where each layer adds scale.
- Steps
- 6
- Subjective questions
- 32
- Objective questions
- 32
The problem and the outcome
Problem: A single server falls over the first time traffic grows 10×.
Outcome: Every layer scales out on its own, with no single point of failure.
Architecture
How it works, step by step
- DNS resolves the domain to the nearest edge location.
- A CDN serves images, scripts and cached pages close to the user.
- The load balancer health-checks servers and spreads requests across availability zones.
- Stateless app servers scale out and in with traffic.
- Sessions and hot reads come from an in-memory cache.
- Writes go to the primary; reads spread across replicas kept in sync by replication.
Tech stack
- Route 53 / Cloudflare DNS
- CDN (CloudFront, Cloudflare)
- Application load balancer
- Auto-scaling app servers or containers
- Redis
- PostgreSQL primary + read replicas
Key design decisions
- Stateless app servers with sessions in Redis or a signed cookie, so any server can take any request and auto-scaling just works.
- Static assets and cacheable pages served from a CDN close to users, taking most traffic off the origin.
- Writes to one primary and reads spread across replicas, accepting a little replication lag on reads.
Common mistakes
- Sticky sessions stored in server memory, so scaling in logs users out.
- Reading your own write from a lagging replica and showing the user stale data.
- Scaling app servers while the single database becomes the real bottleneck.
What to measure
- p95 / p99 latency per endpoint
- CDN offload percentage
- Replica lag in seconds
- CPU and connection-pool saturation
Most-asked interview questions
Subjective questions 32
1Walk through what happens when a user types a URL and presses Enter.Asked almost every time
DNS resolves the name (cached at several levels), the browser opens a TCP and TLS connection, and the request may be answered by a CDN edge. Otherwise it reaches the load balancer, which picks a healthy app server. The server checks the cache, queries the database if needed, renders a response, and the browser parses HTML and fetches CSS, JS and images, many of them from the CDN.
2Horizontal or vertical scaling: when would you choose each?Asked almost every time
Vertical (a bigger machine) is simplest and suits databases early on, but it has a ceiling and a single point of failure. Horizontal (more machines) needs stateless services and a load balancer, but scales further and survives a node failing. Most systems scale the app tier horizontally and the database vertically first, then with replicas and sharding.
3How do you take a single-server app to millions of users?Asked almost every time
Separate the database from the app server, put a load balancer in front of several stateless app servers, add caching (CDN for static assets, Redis for hot data), add read replicas, move slow work to queues and workers, then shard or split services as specific bottlenecks appear, measuring at each step.
4What makes an application server stateless and why does it matter?Asked almost every time
It keeps no user session or files on local disk or memory between requests; sessions live in Redis or tokens, uploads in object storage. Any server can handle any request, so you can add, remove or replace servers freely and auto-scale.
5How do you find the bottleneck in a slow web system?Asked almost every time
Measure end-to-end with tracing and metrics: latency per tier, CPU and memory, database query times, cache hit rates, queue depths and external call latency. Find where time is spent at p95 and p99, then fix that tier rather than scaling everything.
6How do you handle read-your-own-writes with read replicas?Very often asked
Route a user's reads to the primary for a short time after they write, or pin reads that must be fresh (their profile, their order) to the primary. Some systems track the replication position and only read from a replica that has caught up to it.
7What do health checks and graceful shutdown add to scaling?Very often asked
Health checks let the load balancer stop sending traffic to unhealthy instances; graceful shutdown lets instances finish in-flight requests before stopping. Together they make deployments and scale-in events invisible to users.
8How do you serve users in several regions?Very often asked
Use a CDN and DNS-based or anycast routing to send users to the nearest region, deploy app tiers per region, and choose a data strategy: a primary region with replicas for reads, or multi-region databases for writes, accepting extra complexity.
9How do you store user sessions in a scaled system?Very often asked
Use signed and encrypted cookies or JWTs for small stateless sessions, or a shared store like Redis keyed by session ID for server-side sessions. Avoid sticky sessions as the only mechanism because they break when instances disappear.
10How do you move slow work out of the request path?Very often asked
Put jobs such as emails, image processing and reports on a queue, return quickly to the user, and let a separately scaled worker pool process them with retries, reporting progress through polling, webhooks or WebSockets.
11How do you protect the database as traffic grows?Very often asked
Use connection pooling (PgBouncer or RDS Proxy), add indexes, cache hot reads, route reads to replicas, batch writes, set query timeouts and limit expensive endpoints. Sharding comes later, when a single primary cannot handle writes.
12What does a CDN do beyond caching static files?Very often asked
It terminates TLS close to users, caches dynamic responses with appropriate headers, absorbs DDoS attacks, compresses and optimises images, and can run edge logic such as redirects or authentication checks.
13How do you deploy without downtime?Very often asked
Rolling deployments replace instances gradually behind health checks; blue-green switches traffic between two environments; canaries send a small percentage first. Database migrations must be backward compatible (expand, migrate, contract).
14How do you design a system that must survive a full region outage?Very often asked
Run active-active or warm-standby in a second region, replicate data asynchronously with a known recovery point, route users with health-checked DNS or a global load balancer, and rehearse failover regularly. Decide which features may degrade while running from one region.
15How do you keep latency low as you add more services per request?Very often asked
Fan out calls in parallel rather than in sequence, set timeouts and budgets per hop, cache or precompute shared data, use backend-for-frontend aggregation, and trace requests to find the slowest dependency. Tail latency grows with every extra hop.
16What is the expand-and-contract migration pattern?Often asked
Add new columns or tables first (expand), deploy code that writes to both and reads the new one, backfill data, then remove the old structure (contract). Each step works with both old and new code, enabling zero-downtime changes.
17How does auto-scaling decide when to add servers?Often asked
Policies watch metrics such as CPU, request count per target, or queue depth, and add or remove instances to keep them near a target. Scale on the metric closest to user experience, add cooldowns and keep a minimum for sudden spikes.
18What is the role of a reverse proxy?Often asked
It sits in front of app servers to terminate TLS, route requests, compress responses, serve static files, buffer slow clients and add headers, often as Nginx, Envoy or a managed load balancer.
19How do you design for failure in a scalable system?Often asked
Run in several availability zones, add timeouts, retries with backoff and circuit breakers, degrade gracefully (serve cached or partial results), and test failures with game days or chaos experiments.
20What does a database connection pool solve?Often asked
Opening connections is expensive and databases limit their number. A pool reuses a fixed set of connections across requests; external poolers also protect the database when hundreds of app instances or serverless functions connect.
21How do you store user uploads in a scaled app?Often asked
Upload directly to object storage (S3) with pre-signed URLs, save metadata in the database, process files asynchronously, and serve them through a CDN, so app servers never handle large file bytes.
22What are SLOs and how do they guide scaling?Often asked
Service level objectives set targets like 99.9% availability and p95 latency under 300 ms. Error budgets show how much unreliability is acceptable, guiding when to prioritise reliability work and capacity over new features.
23When would you split a monolith into services?Often asked
When teams block each other, parts need very different scaling or technology, or deployments are too risky. Split along clear domain boundaries one piece at a time (strangler pattern), not all at once.
24What does backpressure mean in a web system?Often asked
When a downstream component cannot keep up, it signals upstream to slow down, by bounded queues, 429 or 503 responses, or slower acknowledgements, instead of accepting unlimited work and falling over. Without backpressure, overload spreads and causes cascading failure.
25How do you scale reads with read replicas safely?Often asked
Send reads that can tolerate slight staleness to replicas, keep reads after a user's own write on the primary or a caught-up replica, monitor replication lag, and remove lagging replicas from the pool automatically.
26How do you handle a sudden traffic spike from a marketing email?Often asked
Pre-scale before the send, serve the landing page from the CDN, queue sign-ups and other writes, shed non-essential features with flags, and stagger the email send so traffic arrives over minutes rather than seconds.
27What is a bulkhead and when would you use one?Often asked
A bulkhead isolates resources, such as separate thread pools, connection pools or instances, per dependency or customer class, so one failing dependency or noisy tenant cannot exhaust everything. Use it around slow or unreliable downstream calls.
28What is the difference between latency and bandwidth issues?Sometimes asked
Latency is delay per request (distance, round trips, slow processing); bandwidth is how much data can flow per second. CDNs and fewer round trips fix latency; compression and smaller payloads fix bandwidth limits.
29How do you load-test before a big launch?Sometimes asked
Model realistic traffic (mix of endpoints, think time, peak rates) with tools like k6 or Locust, test against a production-like environment, ramp up gradually, watch every tier's metrics and fix the first bottleneck found.
30What is the thundering herd problem?Sometimes asked
Many clients or processes wake up and hit a resource at the same moment, for example after a cache expiry or a service restart. Jitter, request coalescing and gradual ramp-up prevent it.
31How do feature flags help scaling and releases?Sometimes asked
They separate deploying code from releasing features, allowing gradual rollouts, quick rollback without redeploying, and turning off expensive features during incidents.
32How do you control cloud cost while scaling?Sometimes asked
Right-size instances from real utilisation, use auto-scaling with sensible minimums, move steady load to reserved or savings plans and batch work to spot capacity, cache aggressively, and track cost per request or per user as a metric alongside latency.
Objective questions 32
1What makes an app server safe to auto-scale behind a load balancer?Asked almost every time
Why: If no request depends on state held by one machine, servers can be added or removed freely.
2What makes app servers safe to add or remove freely?Asked almost every time
Why: Any server can handle any request.
3What should be measured first when a system is slow?Asked almost every time
Why: Fix the real bottleneck.
4Where should slow jobs like emails run?Asked almost every time
Why: Users get fast responses.
5What do read replicas mainly scale?Very often asked
Why: Replicas copy the primary's data so reads can be spread out; all writes still go to the primary.
6What does graceful shutdown provide?Very often asked
Why: Deploys stay invisible to users.
7Which deployment sends a small share of traffic to a new version first?Very often asked
Why: Watch metrics before expanding.
8What protects the database from too many connections?Very often asked
Why: Reuses a fixed set of connections.
9The expand-and-contract pattern enables…Very often asked
Why: Each step supports old and new code.
10Which metric is best for auto-scaling web servers?Very often asked
Why: Close to user experience.
11Where should large uploads go?Very often asked
Why: Pre-signed URLs keep bytes off app servers.
12Calls to independent services in one request should be made…Very often asked
Why: Parallel calls bound total latency by the slowest one.
13Backpressure lets a slow component…Very often asked
Why: Bounded work prevents overload from cascading.
14Which layer usually serves images, CSS and JS closest to the user?Often asked
Why: A CDN caches static files at edge locations near users.
15Which pattern splits a monolith gradually?Often asked
Why: Replace pieces one at a time.
16What does an error budget represent?Often asked
Why: Guides reliability work.
17A CDN can also…Often asked
Why: More than static caching.
18Which tool load-tests a web app?Often asked
Why: Model realistic traffic.
19What prevents the thundering herd after a cache expiry?Often asked
Why: Spread or merge requests.
20Running in several availability zones protects against…Often asked
Why: Redundancy across zones.
21Why avoid relying only on sticky sessions?Often asked
Why: Store sessions centrally.
22What does a reverse proxy commonly do?Often asked
Why: Nginx, Envoy or a load balancer.
23Reads right after a user's own write should go to…Often asked
Why: Lagging replicas would show the user stale data.
24A bulkhead protects a system by…Often asked
Why: One failing dependency cannot drain every resource.
25Before a large marketing email, you should…Often asked
Why: Warm capacity and spread arrivals absorb the spike.
26Recovery point objective (RPO) describes…Often asked
Why: RPO is the window of writes you can afford to lose.
27Feature flags separate…Sometimes asked
Why: Enable gradual rollout.
28Bandwidth problems are best fixed by…Sometimes asked
Why: Less data to transfer.
29When should sharding be considered?Sometimes asked
Why: Try replicas and caching first.
30Blue-green deployment means…Sometimes asked
Why: Instant rollback by switching back.
31Which practice tests resilience on purpose?Sometimes asked
Why: Inject failures safely.
32Which work suits cheaper spot capacity?Sometimes asked
Why: Spot instances can be reclaimed at short notice.
Track your progress through every blueprint in your dashboard.
Start learning