System Design Cheatsheet
This article breaks down how to design a web system for scale, starting with scope, use cases, and constraints. It then walks through high-level and component design, scaling strategies (caching, load balancing, replication), performance tuning, reliability, and front-end considerations.
- Start every system design by pinning down use cases and traffic patterns (RPS, read/write ratio) before drawing architecture
- When the database becomes the bottleneck, add Memcached/Redis caching before jumping to vertical or horizontal scaling
- Choose replication vs. partitioning based on whether you need more read capacity or more write throughput
- Isolate shared concerns (auth, caching, DB access) in a platform layer so web, mobile, and API servers can scale independently
Start by defining what the system has to do and who will use it. Nail down user flows, traffic patterns (requests per second, read/write rates) and any special needs like multithreading or heavy writes. Then sketch an abstract architecture: a load balancer feeding service layers, backed by a database cluster and caches. Break services into modules—map each user scenario to one module. Design component APIs, draw out object relationships (use singletons where you need a unique instance, composition for complex objects, inheritance when objects share behavior). Lay out your database schema early on.
Next, spot your bottlenecks. If the database can’t keep up, add in-memory caching (Memcached or Redis) or optimize database caching settings. Scale vertically by beefing up CPU and RAM on key servers. Scale horizontally by adding more machines behind your load balancer. For huge data or analytics, introduce a MapReduce layer (Hadoop, Hive) instead of straining your SQL cluster.
Keep services loosely coupled with a platform layer that handles shared concerns—authentication, caching, database access—so you can spin up web, mobile or API servers independently. Think through concurrency (threads, deadlocks) and networking basics (latency vs. throughput). Know roughly how OS and file systems cache data, and the performance differences between RAM, SSD and spinning disks.
Finally, build resilience and performance into every layer. Replicate or partition your database depending on whether you need more read capacity or write throughput. Use CDNs to serve static assets closer to users. Add full-text search with Sphinx, Lucene or Solr. On the front end, leverage service workers, lazy loading and HTTP/2 bundling. Keep your code modular, follow HTML5 and ARIA standards, and pick JavaScript frameworks that match your performance goals.