|$ curl https://forge-ai.dev/api/markdown?path=docs/system-design
$cat docs/system-design.md
updated Recently·30 min read·published

System Design

System DesignBeginner to Advanced🎯Free Tools
Introduction

System design is the process of defining the architecture, components, modules, interfaces, and data for a system to satisfy specified requirements. It sits at the intersection of computer science fundamentals, engineering pragmatism, and product constraints.

In interviews, system design questions are intentionally ambiguous. The interviewer wants to see how you reason through tradeoffs, communicate assumptions, and evolve a design from a whiteboard sketch to a production-ready architecture. There is rarely a single correct answer — there are only answers that satisfy constraints better or worse.

This tutorial series walks through the core pillars of distributed system design: scalability, databases, caching, microservices, APIs, reliability, security, messaging, and the CAP theorem. It closes with two full case studies — a URL shortener and a real-time chat system — that demonstrate how the pieces fit together.

Why System Design Matters

Every successful product eventually faces the same class of problems: traffic grows 10x overnight, a database becomes a bottleneck, a third-party API goes down, or a security incident exposes customer data. Good system design anticipates these failure modes and builds in margins for growth.

Beyond interviews, system design is the daily work of senior engineers. Choosing between SQL and NoSQL, synchronous and asynchronous communication, strong and eventual consistency — these decisions compound into the quality, cost, and operability of the final product.

ConcernPoor DesignGood Design
ScalabilitySingle server that saturates at peakHorizontally scalable, stateless tier
ReliabilityCascading failures, no retriesCircuit breakers, bulkheads, graceful degradation
MaintainabilityTightly coupled monolithBounded contexts, clear interfaces
CostOver-provisioned idle capacityAuto-scaling, spot instances, caching
SecurityPerimeter-only trust modelZero trust, least privilege, encryption

info

Treat system design as risk management. You are not optimizing for the perfect architecture; you are optimizing for the architecture that fails safely, scales cost-effectively, and can be evolved by a team over years.
The System Design Interview Framework

A structured approach keeps the interview focused and demonstrates senior-level thinking. The framework below is used by engineers at top technology companies and maps cleanly to real-world design processes.

1. Understand Requirements

Clarify functional requirements (what the system must do) and non-functional requirements (latency, throughput, availability, consistency). Ask about scale: daily active users, read/write ratios, data volume, and geographic distribution.

2. Define Constraints

Identify budget, team size, compliance needs, latency budgets, and existing tech stack. Constraints shape every subsequent decision more than raw theory does.

3. Back-of-the-Envelope Math

Estimate QPS, storage, bandwidth, and cache size. Numbers validate whether a proposed design can plausibly meet requirements and expose hidden bottlenecks.

4. High-Level Design

Sketch the system in 5-10 minutes: clients, load balancers, application servers, databases, caches, and message queues. Keep it simple enough to explain in a single narrative.

5. Deep Dives

Drill into the most uncertain or critical components. Common topics include data partitioning, replication, caching strategy, consistency models, and failure handling.

6. Tradeoffs and Alternatives

Discuss what you are giving up for each choice. Interviewers reward self-awareness: knowing when a design is wrong for a different set of constraints is as valuable as knowing why it is right for the current ones.

best practice

Start every design by asking clarifying questions. Designing Twitter without knowing whether the read-heavy timeline or write-heavy posting path dominates will produce the wrong architecture.
Functional vs Non-Functional Requirements

Functional requirements describe behavior. They are usually verbs: post a tweet, shorten a URL, send a message, process a payment. Non-functional requirements describe qualities: the system must serve 99.9% of requests under 100 ms, must survive a single data-center failure, or must encrypt data at rest.

TypeExamplesWhy It Matters
FunctionalCreate account, upload photo, fetch feedDefines API surface and data model
Scalability1M DAU, 10K writes/sec, 100K reads/secDrives sharding, caching, and load balancing
Availability99.99% uptime, RTO < 1 hourRequires redundancy and runbooks
Latencyp99 < 200 ms for readsPushes data closer to users via CDN/cache
ConsistencyPayments: strong; likes: eventualInfluences database and replication choices
DurabilityZero data loss for committed writesRequires replication, backups, and WAL

warning

Do not treat requirements as immutable. In a real interview, requirements evolve as the conversation progresses. State your assumptions explicitly so the interviewer can challenge them.
Back-of-the-Envelope Estimation

Capacity estimation turns vague scale targets into concrete numbers. The goal is not precision; it is order-of-magnitude correctness. Use round numbers and justify assumptions.

capacity-estimate.txt
TEXT
1Example: Design a URL shortener for 100M monthly active users.
2
3Assumptions:
4- 10% of MAU create a short URL daily = 10M writes/day
5- Each shortened URL is read 100 times/day = 1B reads/day
6- Average slug length: 7 bytes; metadata: 500 bytes/row
7- Peak traffic = 5x average
8
9Writes per second: 10M / 86,400 ≈ 116 writes/sec (peak ≈ 580)
10Reads per second: 1B / 86,400 ≈ 11,574 reads/sec (peak ≈ 57,870)
11Daily new storage: 10M rows × 507 bytes ≈ 4.7 GB/day
12Yearly storage: 4.7 GB × 365 ≈ 1.7 TB/year (raw)
13With 3x replication: ≈ 5.1 TB/year

These numbers immediately tell you that reads dominate writes, so a caching layer is essential. They also tell you that a single relational database could handle the write volume but would struggle with the read volume without replicas or a cache.

🔥

pro tip

Memorize a few useful constants: 1 request/day ≈ 0.0116 rps, an SSD delivers ~100K random IOPS, a single server can sustain ~10K-100K concurrent connections depending on workload, and a cross-continent round trip is ~150 ms.
High-Level Design

The high-level design is a conceptual map of the system. It should be technology-agnostic at first — talk about load balancers, application servers, caches, databases, and queues before naming specific products. Once the shape is agreed upon, you can substitute concrete technologies.

high-level-architecture.txt
TEXT
1┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐
2│ Client │────▶│ CDN │────▶│ Load Balancer │
3│ (Browser) │ │ (Static) │ │ (Round-Robin/L7) │
4└─────────────┘ └─────────────┘ └──────────┬──────────┘
5
6 ┌────────────────────────┼────────────────────────┐
7 │ │ │
8 ┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
9 │ App Server │ │ App Server │ │ App Server │
10 │ (Stateless)│ │ (Stateless)│ │ (Stateless)│
11 └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
12 │ │ │
13 └──────────────┬─────────┴──────────┬─────────────┘
14 │ │
15 ┌──────▼──────┐ ┌──────▼──────┐
16 │ Cache │ │ Queue │
17 │ (Redis) │ │ (Kafka) │
18 └──────┬──────┘ └──────┬──────┘
19 │ │
20 ┌──────▼──────┐ ┌──────▼──────┐
21 │ Database │ │ Workers │
22 │(Primary/Rep)│ │ (Async) │
23 └─────────────┘ └─────────────┘

This canonical layered architecture separates concerns: the CDN handles static assets and edge caching, the load balancer distributes traffic, stateless app servers hold no session data, the cache absorbs hot reads, the database is the source of truth, and the queue decouples heavy work.

📝

note

Stateless application servers are the default choice for scalable web systems. If you need state — such as WebSocket connections — use a dedicated stateful layer or externalize state to Redis so that any app server can handle any request.
Deep Dives and Bottlenecks

After the high-level design, the interviewer will push on the weakest or most interesting parts of the system. Typical deep-dive topics include data modeling, sharding strategy, cache invalidation, consistency guarantees, and failure scenarios.

ComponentCommon QuestionsKey Techniques
DatabaseHow do you scale writes? Handle hot shards?Sharding, replication, indexing, partitioning
CacheWhat happens on a cache miss? How do you keep data fresh?Cache-aside, write-through, TTL, invalidation
Load BalancerHow do you route sticky sessions? Detect failures?Health checks, consistent hashing, least-connections
Message QueueWhat if a consumer crashes? How do you order events?Idempotency, at-least-once, partitions, offsets
APIHow do you version? Prevent abuse?Versioned routes, rate limiting, idempotency keys

best practice

Always identify the bottleneck before optimizing. A cache cannot fix an O(n²) query. A load balancer cannot fix a single-threaded database. Measure first, then scale the right component.
Evaluating Tradeoffs

Every design decision is a tradeoff. The hallmark of a senior engineer is the ability to articulate what is gained and lost. Do not present choices as universally good or bad; present them as context-dependent.

TradeoffOption AOption BWhen to Choose
SQL vs NoSQLStrong consistency, joinsHorizontal scale, flexible schemaSQL for relational data; NoSQL for high-write/scale
Sync vs AsyncSimpler, stronger consistencyDecoupled, resilient, higher throughputSync for user-facing critical paths; async for background work
Strong vs EventualCorrectness, complexityAvailability, lower latencyStrong for financial data; eventual for social counters
Monolith vs MicroservicesSimpler deployment, lower overheadIndependent scale, team autonomyMonolith for small teams; services for large orgs

info

Use the phrase "It depends on..." often. Interviewers expect you to connect every choice back to requirements, constraints, and risk tolerance.
What to Study Next

The following pages explore each pillar in depth. Read them in order if you are new to system design, or jump to the topics most relevant to your interview or project.

🔥

pro tip

Practice out loud. The system design interview is a communication exercise disguised as a technical exercise. A correct architecture explained poorly scores lower than a flawed architecture discussed honestly.
$Blueprint — Engineering Documentation·Section ID: SD-01·Revision: 1.0