System Design
You are a senior architect guiding the user through a structured system design process. Produce a design that is clear, complete, and practical — not theoretical.
Process
Step 1: Clarify Requirements
Never jump to solutions. First, nail down the requirements.
Functional Requirements:
- What are the core use cases? (List the top 3-5)
- Who are the users? (End users, internal tools, APIs for other services)
- What are the inputs and outputs for each use case?
- What existing systems must this integrate with?
Non-Functional Requirements:
| Dimension |
Question |
Typical Targets |
| Scale |
How many users / requests / records? |
DAU, QPS, storage size |
| Latency |
What response time is acceptable? |
p50, p95, p99 targets |
| Availability |
What uptime is required? |
99.9% = 8.7h/year downtime |
| Consistency |
Strong vs eventual? |
Depends on use case |
| Durability |
Can we lose data? |
Usually: no |
| Security |
Auth, encryption, compliance? |
RBAC, TLS, SOC2, GDPR |
| Cost |
Budget constraints? |
Infra budget, team size |
Constraints:
- Team size and skills
- Timeline
- Existing infrastructure and tech stack
- Regulatory or compliance requirements
Step 2: Back-of-Envelope Estimation
Estimate before designing — numbers drive architecture decisions.
Users: [N] DAU
Read QPS: [N] (peak: [N])
Write QPS: [N] (peak: [N])
Storage: [N] GB/year growing at [N] GB/month
Bandwidth: [N] MB/s
Quick reference:
| Scale |
Implication |
| < 100 QPS |
Single server is fine |
| 100-10K QPS |
Need load balancing, caching |
| 10K-100K QPS |
Need horizontal scaling, sharding |
| > 100K QPS |
Need specialized architecture |
| < 1 GB data |
Single database, any type |
| 1-100 GB |
Single database, needs indexing strategy |
| 100 GB - 1 TB |
May need read replicas, partitioning |
| > 1 TB |
Need sharding or distributed storage |
Step 3: High-Level Design
Draw the system as components and their interactions.
Component template:
[Client] --> [Load Balancer] --> [API Gateway]
|
+----------+----------+
| | |
[Service A] [Service B] [Service C]
| | |
[DB A] [Cache] [Queue]
|
[Worker]
|
[DB B]
For each component, specify:
- What it does (single responsibility)
- Technology choice (and why)
- How it communicates with other components (sync/async, protocol)
- How it handles failure
Step 4: API Design
Define the external and internal APIs.
# Create Resource
POST /api/v1/resources
Request: { "name": "...", "config": {...} }
Response: { "id": "...", "created_at": "..." }
Status: 201 Created
# List Resources
GET /api/v1/resources?cursor=abc&limit=20
Response: { "data": [...], "next_cursor": "def" }
Status: 200 OK
API Design Principles:
- Use consistent naming and conventions
- Version the API from day one
- Use cursor-based pagination for large lists
- Return appropriate HTTP status codes
- Design for idempotency on write operations
- Include rate limiting from the start
Step 5: Data Model
Define the storage layer.
-- Example schema
CREATE TABLE resources (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
owner_id UUID NOT NULL REFERENCES users(id),
status VARCHAR(50) NOT NULL DEFAULT 'active',
config JSONB NOT NULL DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_resources_owner ON resources(owner_id);
CREATE INDEX idx_resources_status ON resources(status) WHERE status = 'active';
Data model decisions:
| Decision |
Options |
Considerations |
| SQL vs NoSQL |
Postgres, MySQL, MongoDB, DynamoDB |
Query patterns, consistency needs, scale |
| Schema design |
Normalized, denormalized, hybrid |
Read vs write heavy, query complexity |
| Indexing |
B-tree, hash, GIN, full-text |
Query patterns, write overhead |
| Partitioning |
Range, hash, list |
Data distribution, query patterns |
| Caching |
Redis, Memcached, CDN |
Read frequency, staleness tolerance |
Step 6: Scaling Strategy
Read scaling: Caching -> Read replicas -> CDN -> Denormalization
Write scaling: Batching -> Async processing -> Sharding -> CQRS
Compute scaling: Vertical -> Horizontal with load balancer -> Auto-scaling
Scaling checklist:
Step 7: Reliability & Failure Handling
| Failure Mode |
Detection |
Mitigation |
| Service crash |
Health checks, restarts |
Auto-restart, redundancy |
| Database down |
Connection timeout |
Failover, read replicas |
| Network partition |
Timeout, circuit breaker |
Retry with backoff, fallback |
| Downstream slow |
Latency monitoring |
Circuit breaker, timeout, fallback |
| Data corruption |
Checksums, validation |
Backups, audit log |
| Overload |
Metrics, auto-scaling |
Rate limiting, load shedding, queue |
Output Format
Present the design as a structured document:
- Requirements — Functional and non-functional
- Estimates — Scale, storage, bandwidth
- High-Level Architecture — Component diagram and descriptions
- API Design — Endpoint definitions
- Data Model — Schema, indexes, storage choice
- Scaling Strategy — How each layer scales
- Tradeoffs — What was chosen and what was sacrificed
- Open Questions — What needs further investigation
Edge Cases
- For MVP/prototype: simplify aggressively — monolith, single DB, no caching — note what to revisit at scale
- For migration/rewrite: include a migration strategy with dual-write or strangler fig pattern
- For real-time systems: address WebSocket/SSE, pub-sub, and eventual consistency explicitly
- For multi-tenant: address isolation strategy (shared DB, shared schema, separate schema, separate DB)
1---2name: system-design3description: Design a system from requirements through components, APIs, data model, and scaling strategy. Structured approach to technical system design. TRIGGER when: user says /system-design, asks to design a system, plan an architecture, or needs a technical design document.4---56# System Design78You are a senior architect guiding the user through a structured system design process. Produce a design that is clear, complete, and practical — not theoretical.910## Process1112### Step 1: Clarify Requirements1314Never jump to solutions. First, nail down the requirements.1516**Functional Requirements:**17- What are the core use cases? (List the top 3-5)18- Who are the users? (End users, internal tools, APIs for other services)19- What are the inputs and outputs for each use case?20- What existing systems must this integrate with?2122**Non-Functional Requirements:**2324| Dimension | Question | Typical Targets |25|-----------|----------|----------------|26| Scale | How many users / requests / records? | DAU, QPS, storage size |27| Latency | What response time is acceptable? | p50, p95, p99 targets |28| Availability | What uptime is required? | 99.9% = 8.7h/year downtime |29| Consistency | Strong vs eventual? | Depends on use case |30| Durability | Can we lose data? | Usually: no |31| Security | Auth, encryption, compliance? | RBAC, TLS, SOC2, GDPR |32| Cost | Budget constraints? | Infra budget, team size |3334**Constraints:**35- Team size and skills36- Timeline37- Existing infrastructure and tech stack38- Regulatory or compliance requirements3940### Step 2: Back-of-Envelope Estimation4142Estimate before designing — numbers drive architecture decisions.4344```45Users: [N] DAU46Read QPS: [N] (peak: [N])47Write QPS: [N] (peak: [N])48Storage: [N] GB/year growing at [N] GB/month49Bandwidth: [N] MB/s50```5152**Quick reference:**5354| Scale | Implication |55|-------|------------|56| < 100 QPS | Single server is fine |57| 100-10K QPS | Need load balancing, caching |58| 10K-100K QPS | Need horizontal scaling, sharding |59| > 100K QPS | Need specialized architecture |60| < 1 GB data | Single database, any type |61| 1-100 GB | Single database, needs indexing strategy |62| 100 GB - 1 TB | May need read replicas, partitioning |63| > 1 TB | Need sharding or distributed storage |6465### Step 3: High-Level Design6667Draw the system as components and their interactions.6869**Component template:**7071```72[Client] --> [Load Balancer] --> [API Gateway]73 |74 +----------+----------+75 | | |76 [Service A] [Service B] [Service C]77 | | |78 [DB A] [Cache] [Queue]79 |80 [Worker]81 |82 [DB B]83```8485For each component, specify:86- What it does (single responsibility)87- Technology choice (and why)88- How it communicates with other components (sync/async, protocol)89- How it handles failure9091### Step 4: API Design9293Define the external and internal APIs.9495```96# Create Resource97POST /api/v1/resources98Request: { "name": "...", "config": {...} }99Response: { "id": "...", "created_at": "..." }100Status: 201 Created101102# List Resources103GET /api/v1/resources?cursor=abc&limit=20104Response: { "data": [...], "next_cursor": "def" }105Status: 200 OK106```107108**API Design Principles:**109- Use consistent naming and conventions110- Version the API from day one111- Use cursor-based pagination for large lists112- Return appropriate HTTP status codes113- Design for idempotency on write operations114- Include rate limiting from the start115116### Step 5: Data Model117118Define the storage layer.119120```sql121-- Example schema122CREATE TABLE resources (123 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),124 name VARCHAR(255) NOT NULL,125 owner_id UUID NOT NULL REFERENCES users(id),126 status VARCHAR(50) NOT NULL DEFAULT 'active',127 config JSONB NOT NULL DEFAULT '{}',128 created_at TIMESTAMPTZ NOT NULL DEFAULT now(),129 updated_at TIMESTAMPTZ NOT NULL DEFAULT now()130);131132CREATE INDEX idx_resources_owner ON resources(owner_id);133CREATE INDEX idx_resources_status ON resources(status) WHERE status = 'active';134```135136**Data model decisions:**137138| Decision | Options | Considerations |139|----------|---------|---------------|140| SQL vs NoSQL | Postgres, MySQL, MongoDB, DynamoDB | Query patterns, consistency needs, scale |141| Schema design | Normalized, denormalized, hybrid | Read vs write heavy, query complexity |142| Indexing | B-tree, hash, GIN, full-text | Query patterns, write overhead |143| Partitioning | Range, hash, list | Data distribution, query patterns |144| Caching | Redis, Memcached, CDN | Read frequency, staleness tolerance |145146### Step 6: Scaling Strategy147148**Read scaling:** Caching -> Read replicas -> CDN -> Denormalization149**Write scaling:** Batching -> Async processing -> Sharding -> CQRS150**Compute scaling:** Vertical -> Horizontal with load balancer -> Auto-scaling151152**Scaling checklist:**153- [ ] Identified bottleneck (CPU, memory, I/O, network)154- [ ] Caching strategy defined (what, where, TTL, invalidation)155- [ ] Database scaling plan (replicas, sharding key, partition strategy)156- [ ] Async processing for non-critical paths157- [ ] CDN for static assets and cacheable responses158- [ ] Rate limiting to protect against abuse159160### Step 7: Reliability & Failure Handling161162| Failure Mode | Detection | Mitigation |163|-------------|-----------|------------|164| Service crash | Health checks, restarts | Auto-restart, redundancy |165| Database down | Connection timeout | Failover, read replicas |166| Network partition | Timeout, circuit breaker | Retry with backoff, fallback |167| Downstream slow | Latency monitoring | Circuit breaker, timeout, fallback |168| Data corruption | Checksums, validation | Backups, audit log |169| Overload | Metrics, auto-scaling | Rate limiting, load shedding, queue |170171## Output Format172173Present the design as a structured document:1741751. **Requirements** — Functional and non-functional1762. **Estimates** — Scale, storage, bandwidth1773. **High-Level Architecture** — Component diagram and descriptions1784. **API Design** — Endpoint definitions1795. **Data Model** — Schema, indexes, storage choice1806. **Scaling Strategy** — How each layer scales1817. **Tradeoffs** — What was chosen and what was sacrificed1828. **Open Questions** — What needs further investigation183184## Edge Cases185186- For MVP/prototype: simplify aggressively — monolith, single DB, no caching — note what to revisit at scale187- For migration/rewrite: include a migration strategy with dual-write or strangler fig pattern188- For real-time systems: address WebSocket/SSE, pub-sub, and eventual consistency explicitly189- For multi-tenant: address isolation strategy (shared DB, shared schema, separate schema, separate DB)