System Design Basics
Sure! Here are basic System Design notes written in clean, structured Markdown syntax — perfect for interviews or quick revision.
🏗️ System Design Basics
📘 1. What is System Design?
System Design is the process of defining the architecture, components, modules, interfaces, and data flow for a large-scale software system.
It focuses on how to build scalable, reliable, and maintainable systems that can handle millions of users efficiently.
🧩 2. Key Goals of System Design
- Scalability → Handle increasing load (users, traffic, data).
- Reliability → Continue functioning even with failures.
- Availability → Keep the system accessible most of the time (e.g., 99.99%).
- Maintainability → Easy to update, debug, and improve.
- Performance → Fast response times, efficient resource usage.
⚙️ 3. Core Components of a System
| Component | Description |
|---|---|
| Client | The user interface or application making requests (browser, mobile app). |
| API Gateway | Entry point for client requests — routes traffic to backend services. |
| Application Server | Runs business logic (e.g., Node.js, Django, Spring Boot). |
| Database | Stores structured or unstructured data (SQL or NoSQL). |
| Cache | Temporary high-speed storage (e.g., Redis, Memcached) to reduce DB load. |
| Load Balancer | Distributes requests evenly across multiple servers. |
| Message Queue | Decouples components and handles async tasks (e.g., Kafka, RabbitMQ). |
| CDN (Content Delivery Network) | Delivers static content closer to users to reduce latency. |
| Monitoring & Logging | Tools to track system health and diagnose issues (e.g., Prometheus, ELK). |
🗂️ 4. Types of Databases
| Type | Use Case | Example |
|---|---|---|
| SQL (Relational) | Structured data, strong consistency | PostgreSQL, MySQL |
| NoSQL (Document) | Unstructured, flexible schema | MongoDB, DynamoDB |
| Key-Value Store | Fast lookups, caching | Redis, Memcached |
| Wide Column Store | Analytics, big data | Cassandra, HBase |
| Graph Database | Relationships, social networks | Neo4j |
⚖️ 5. Scaling Strategies
1. Vertical Scaling (Scaling Up)
- Add more CPU/RAM to a single machine.
- ✅ Easy to implement
- ❌ Hardware limits and cost grow fast
2. Horizontal Scaling (Scaling Out)
- Add more servers to handle traffic.
- ✅ Better fault tolerance
- ❌ Requires load balancing and distributed data management
📡 6. Load Balancing
Goal: Distribute incoming traffic across multiple servers.
Common Algorithms
- Round Robin – Sequential distribution
- Least Connections – Send to server with fewest active connections
- IP Hashing – Based on client IP
- Weighted Round Robin – Servers get different weights
Popular Tools
- Nginx
- HAProxy
- AWS Elastic Load Balancer (ELB)
⚡ 7. Caching
Why?
Reduce latency, DB queries, and improve performance.
Types
- Client-side cache: Browser/local storage
- Server-side cache: Redis, Memcached
- CDN cache: Static content caching
Cache Invalidation Strategies
- Write-through: Write to cache and DB simultaneously
- Write-around: Write only to DB, cache updated on next read
- Write-back: Write to cache, persist to DB later
📬 8. Message Queues & Asynchronous Processing
Used to decouple services and handle background jobs.
Examples
- Kafka
- RabbitMQ
- AWS SQS
Use Cases
- Sending emails or notifications
- Processing uploads
- Logging or analytics pipelines
🧱 9. CAP Theorem
| Property | Meaning |
|---|---|
| C - Consistency | Every read receives the latest write or an error. |
| A - Availability | Every request receives a non-error response. |
| P - Partition Tolerance | System continues to work despite network failures. |
⚠️ In a distributed system, you can only guarantee two of the three (CA, CP, or AP).
🧭 10. Design Patterns for System Design
| Pattern | Description |
|---|---|
| Microservices | Break system into small independent services. |
| Monolithic | Single large codebase (simple but harder to scale). |
| Event-driven | Components react to events asynchronously. |
| CQRS | Separate read and write models for performance. |
| Pub/Sub | Publishers broadcast messages; subscribers listen. |
📈 11. Common Design Topics for Interviews
| System | Concepts to Know |
|---|---|
| URL Shortener (e.g., TinyURL) | Hashing, Database indexing, Cache |
| Instagram / Twitter Feed | Sharding, Caching, Queueing |
| Chat App (e.g., WhatsApp) | WebSockets, Message queues, Delivery status |
| E-commerce Platform | Inventory management, Database design, Payment flow |
| Video Streaming (e.g., YouTube) | CDN, Chunking, Adaptive bitrate streaming |
| Search Autocomplete | Trie, Caching, Debouncing |
🧮 12. Key Metrics to Monitor
- Latency (ms) – Response time
- Throughput (req/sec) – Number of handled requests
- Availability (%) – Uptime reliability
- Error Rate (%) – Failed requests
- Scalability – Performance under load
🧠 13. Step-by-Step Approach to a System Design Interview
- Clarify requirements → Functional + Non-functional
- Estimate scale → QPS, data size, users
- Design high-level architecture → Components & data flow
- Define database schema → SQL/NoSQL choice
- Plan scaling & fault tolerance
- Discuss trade-offs → Consistency vs availability, cost vs performance
- Summarize the design visually or verbally
🧩 14. Tools & Technologies to Know
- Frontend: React, Next.js, REST, WebSockets
- Backend: Node.js, Nest.js, Express, Spring Boot
- Databases: MongoDB, PostgreSQL, Redis
- Cloud & DevOps: AWS, Docker, Kubernetes
- Monitoring: Grafana, Prometheus, ELK Stack
🏁 15. Final Tips
- Always start simple, then iterate into scalability.
- Be explicit about assumptions (users, requests/sec, data size).
- Use diagrams — even rough sketches help a lot.
- Show trade-off thinking (cost, latency, complexity).
- Practice explaining designs for common systems.