When this skill is activated, always start your first response with the 🧢 emoji.
System Design
A practical framework for designing distributed systems and architecting scalable services. This skill covers the core building blocks - load balancers, databases, caches, queues, and CDNs - plus the trade-off reasoning required to use them well. It is built around interview scenarios because they compress the full design process into a repeatable structure you can also apply in real-world architecture decisions. Agents can use this skill to work through any system design problem from capacity estimation through detailed component design.
When to use this skill
Trigger this skill when the user:
- Asks "how would you design X?" where X is a product or service
- Needs to choose between SQL and NoSQL databases
- Is evaluating load balancing, sharding, or replication strategies
- Asks about the CAP theorem or consistency vs availability trade-offs
- Is designing a caching strategy (what to cache, where, how to invalidate)
- Needs to estimate traffic, storage, or bandwidth for a system
- Is preparing for a system design interview
- Asks about rate limiting, API gateways, or CDN placement
Do NOT trigger this skill for:
- Line-level code review or specific algorithm implementations (use a coding skill)
- DevOps/infrastructure provisioning details like Terraform or Kubernetes manifests
Key principles
- Start simple and justify complexity - Design the simplest system that satisfies
the requirements. Introduce each new component (queue, cache, shard) only when you can name the specific constraint it solves. Complexity is a cost, not a feature.
- Network partitions will happen - choose C or A - CAP theorem says distributed
systems must sacrifice either consistency or availability during a partition. You cannot avoid partitions (P is not a choice). Pick CP for financial and inventory data; pick AP for feeds, caches, and preferences.
- Scale horizontally, partition vertically - Stateless services scale out behind
a load balancer. Data scales by separating hot from cold paths: read replicas before sharding, sharding before multi-region. Vertical scaling buys time; horizontal scaling buys headroom.
- Design for failure at every layer - Every service will go down. Every disk will
fill. Design fallback behavior before the happy path. Timeouts, retries with backoff, circuit breakers, and bulkheads are not optional refinements - they are table stakes.
- Single responsibility for components - A component that does two things will be
bad at both. Load balancers balance load. Caches serve reads. Queues decouple producers from consumers. Mixing responsibilities creates invisible coupling that makes the system fragile under load.
Core concepts
System design assembles six core building blocks. Each solves a specific problem.
Load balancers distribute requests across backend instances. L4 balancers route by TCP/IP; L7 balancers route by HTTP path, headers, and cookies. Use L7 for HTTP services. Algorithms: round-robin (default), least-connections (when request latency varies), consistent hashing (when you need sticky routing, e.g., cache affinity).
Caches reduce read latency and database load. Sit in front of the database. Patterns: cache-aside (default), write-through (strong consistency), write-behind (high write throughput, tolerate loss). Key concerns: TTL, invalidation strategy, and stampede prevention. Redis is the default; Memcached only when pure key-value at massive scale.
Databases are the source of truth. SQL for structured data with ACID transactions; NoSQL for scale, flexible schemas, or specific access patterns. Read replicas for read-heavy workloads. Sharding for write-heavy workloads that exceed one node.
Message queues decouple producers from consumers and absorb traffic spikes. Use for async work, fan-out events, and unreliable downstream dependencies. Always configure a dead-letter queue. SQS for AWS-native work; Kafka for high-throughput event streaming or replay.
CDNs cache static assets and edge-terminate TLS close to users. Reduces origin load and cuts latency for geographically distributed users. Use for images, JS/CSS, and any content with high read-to-write ratio.
API gateways enforce cross-cutting concerns - auth, rate limiting, request logging, TLS termination - at a single entry point. Never build a custom gateway; use Kong, Envoy, or a managed provider.
Common tasks
Design a URL shortener
Clarifying questions: Read-heavy or write-heavy? Need analytics? Custom slugs? Global or single-region?
Components:
- API service (stateless, horizontally scaled) behind L7 load balancer
- Key generation service - pre-generate Base62 short codes in batches and store
in a pool; avoids hot write path
- Database - a relational DB works at moderate scale; switch to Cassandra for
multi-region or >100k writes/sec
- Cache (Redis) - store short_code -> long_url mappings; TTL 24 hours; cache-aside
Redirect flow: Client hits CDN -> cache hit returns 301/302 -> cache miss reads DB -> populates cache -> returns redirect.
Scale signal: 100M URLs stored, 10B reads/day -> cache hit rate must be >99% to protect the DB.
Design a rate limiter
Algorithm choices:
- Token bucket (default) - allows bursts up to bucket capacity; fills at a
constant rate. Best for user-facing APIs.
- Fixed window - simple counter per time window. Prone to burst at window edge.
- Sliding window log - exact, but memory-intensive.
- Sliding window counter - approximation using two fixed windows. Good balance.
Storage: Redis with atomic INCR and EXPIRE. Single Redis node is enough up to ~50k RPS per rule; use Redis Cluster for more.
Placement: In the API gateway (preferred) or as middleware. Always return X-RateLimit-Remaining and Retry-After headers with 429 responses.
Distributed concern: With multiple gateway nodes, the counter must be centralized (Redis) - local counters undercount.
Design a notification system
Components:
- Notification API - accepts events from internal services
- Router service - reads user preferences and determines channels (push, email, SMS)
- Channel-specific workers (separate services) - dequeued from per-channel queues
- Template service - renders notification copy
- Delivery tracking - records sent/delivered/failed per notification
Queue design: One queue per channel (push-queue, email-queue, sms-queue). Isolates failure - SMS provider outage does not back up email delivery.
Critical path vs non-critical path:
- OTP and security alerts: synchronous, priority queue
- Marketing and social notifications: async, best-effort, can be batched
Design a chat system
Protocol: WebSockets for real-time bidirectional messaging. Long-polling as fallback for restrictive networks.
Storage split:
- Message history: Cassandra, keyed by (channel_id, timestamp). Append-only,
high write throughput, easy time-range queries.
- User presence and metadata: Redis (in-memory, fast reads).
- User and channel info: PostgreSQL (relational, ACID).
Fanout: When a user sends a message, the server writes to the DB and then publishes to a pub/sub channel (Redis Pub/Sub or Kafka). Each recipient's connection server subscribes to relevant channels and pushes to the WebSocket.
Scale concern: Connection servers are stateful (WebSockets). Route users to the same connection server with consistent hashing. Use a service mesh for connection server discovery.
Choose between SQL vs NoSQL
Use this decision table:
| Need | Choose | |---|---| | ACID transactions across multiple entities | SQL | | Complex joins and ad-hoc queries | SQL | | Strict schema with referential integrity | SQL | | Horizontal write scaling beyond single no