Skip to content

๐ŸŽฏ System Design Interview โ€” Master Template โ€‹

AdvancedAdvanced3+ yrs experience Deep technical material โ€” distributed-systems theory, low-level implementation details, and case studies of real production systems.Prerequisites: Production experience with at least one distributed system. Comfort reading research papers and RFCs.

Use this framework for every system design interview. Interviewers expect structure.

TIP

New to Case Studies? Read our Guidelines on How to Manage & Study Case Studies first to maximize your learning.


โฑ๏ธ 45-Minute Interview Timeline โ€‹


๐Ÿ“‹ Step-by-Step Framework โ€‹

Step 1: Clarify Requirements (5 min) โ€‹

ALWAYS ask these before drawing anything:

Functional:
  "What are the core features? Can I focus on X, Y, Z?"
  "Do we need auth? Analytics? Admin panel?"

Scale:
  "How many users? Daily active users?"
  "Read-heavy or write-heavy?"
  "Is this global or a single region?"

Constraints:
  "Any tech constraints? Existing infrastructure?"
  "What latency targets matter?"
  "How much data retention? Any compliance requirements?"

Step 2: Back-of-Envelope Estimates (5 min) โ€‹

Template:
  DAU (Daily Active Users): ___
  Requests/sec (peak):       DAU ร— actions_per_day / 86,400
  Storage/day:               requests ร— data_per_request
  Storage total:             storage/day ร— retention_days
  Bandwidth:                 requests/sec ร— data_per_request

Example for Twitter-scale:
  DAU: 200M
  Tweets/day: 500M โ†’ ~5,800/sec
  Storage/tweet: 300 bytes
  Storage/day: 500M ร— 300 = 150 GB/day
  5-year storage: 150 GB ร— 365 ร— 5 = ~274 TB

Step 3: High-Level Design (5 min) โ€‹

Draw these 6 boxes first, always:

Example: Simple App Server wrapping Cache & DB โ€‹

javascript
const express = require("express");
const app = express();
const cache = require("./myCacheLayer"); // e.g., Redis client
const db = require("./myDatabaseLayer"); // e.g., Postgres client

app.get("/api/v1/user/:id", async (req, res) => {
  const userId = req.params.id;

  try {
    // 1. Check Cache first (The Load Balancer routes here)
    const cachedUser = await cache.get(`user:${userId}`);
    if (cachedUser) {
      return res.json(JSON.parse(cachedUser));
    }

    // 2. Cache Miss: Query Database
    const user = await db.query("SELECT * FROM users WHERE id = ?", [userId]);
    if (!user) return res.status(404).send("Not found");

    // 3. Populate Cache for next time
    await cache.setex(`user:${userId}`, 3600, JSON.stringify(user));

    // 4. Return to Client
    res.json(user);
  } catch (error) {
    res.status(500).send("Server Error");
  }
});

Step 4: API Design (5 min) โ€‹

REST Convention:

  • POST /resource โ†’ create
  • GET /resource/:id โ†’ read
  • PUT /resource/:id โ†’ update (full)
  • PATCH /resource/:id โ†’ update (partial)
  • DELETE /resource/:id โ†’ delete

Example: URL Shortener API Routes โ€‹

javascript
const express = require("express");
const router = express.Router();

// CREATE: POST /api/v1/urls
router.post("/urls", async (req, res) => {
  const { longUrl } = req.body;
  const shortCode = await urlService.shorten(longUrl);
  res.status(201).json({ shortUrl: `http://short.ly/${shortCode}`, longUrl });
});

// READ: GET /api/v1/urls/:shortCode (Actually redirects)
router.get("/urls/:shortCode", async (req, res) => {
  const longUrl = await urlService.resolve(req.params.shortCode);
  res.redirect(302, longUrl);
});

// DELETE: DELETE /api/v1/urls/:shortCode
router.delete("/urls/:shortCode", async (req, res) => {
  // Requires authentication/authorization
  await urlService.delete(req.params.shortCode);
  res.status(204).send(); // 204 No Content
});

module.exports = router;

Step 5: Database Design (5 min) โ€‹

Questions to answer:
  1. What data do I need to store?
  2. SQL or NoSQL? Why?
  3. What are the access patterns? (query shapes)
  4. What indexes do I need?
  5. How do I handle relationships?

SQL (PostgreSQL/MySQL):
  - User accounts
  - Transactional data (orders, payments)
  - Complex relational queries

NoSQL:
  - Cassandra: write-heavy, time-series (messages, events)
  - Redis: cache, sessions, leaderboards, geolocation
  - Elasticsearch: full-text search
  - MongoDB: flexible schema, document storage
  - DynamoDB: serverless, managed, key-value

Step 6: Scale & Reliability (10 min) โ€‹

Scaling Checklist:
  โ–ก Load balancer in front of app servers
  โ–ก Multiple availability zones
  โ–ก Database replication (read replicas)
  โ–ก Caching layer (Redis)
  โ–ก CDN for static assets
  โ–ก Async processing (message queue)
  โ–ก Rate limiting

Reliability Checklist:
  โ–ก Circuit breakers between services
  โ–ก Retry with exponential backoff
  โ–ก Health checks + auto-restart
  โ–ก Data backups + disaster recovery
  โ–ก Graceful degradation

Step 7: Trade-offs (5 min) โ€‹

Every design choice has trade-offs. Name yours:

"I chose Cassandra for message storage because of its write throughput,
 but the trade-off is that complex JOIN queries aren't supported."

"I used eventual consistency in the feed service for performance,
 but users might see slightly stale data for a few seconds."

"I'm pre-computing feeds on write (fan-out on write), which uses more storage
 but makes reads instant. For celebrity accounts, I switch to fan-out on read."

๐Ÿšซ Common Mistakes to Avoid โ€‹

MistakeFix
Jumping to solution without clarifyingAlways spend 5 min on requirements
Not thinking about scaleDo back-of-envelope estimates
Single point of failureAdd redundancy everywhere
Forgetting the cacheMost read-heavy systems need Redis
Ignoring failure modes"What if the DB goes down?"
Overly complex from the startStart simple, scale incrementally
Not discussing trade-offsEvery choice has costs โ€” say them

๐Ÿ’ก Common Patterns to Memorize โ€‹


๐Ÿ† Systems to Master (Priority Order) โ€‹

Beginner โ€‹

  1. URL Shortener โ† Start here
  2. Pastebin
  3. Rate Limiter

Intermediate โ€‹

  1. Twitter/Instagram feed
  2. WhatsApp/Chat Application
  3. File storage (Dropbox/Google Drive)

Advanced โ€‹

  1. Uber/ride-sharing
  2. Netflix/Video Streaming
  3. E-Commerce Platform (Microservices) โ† Full system design
  4. Search autocomplete
  5. Distributed key-value store (like DynamoDB)
  6. Web crawler
  7. Ad click aggregation

๐Ÿ“Š Case Study Quick Reference โ€‹

Case StudyDifficultyCategoryKey Patterns
URL Shortener๐ŸŸข BeginnerRead-HeavyBase62, Redis Cache, ID Generator
Chat Application๐ŸŸก IntermediateReal-TimeWebSocket, Kafka, Cassandra, Fan-out
Video Streaming๐Ÿ”ด AdvancedBandwidth-IntensiveCDN, HLS/DASH, DAG Transcoding
E-Commerce Microservices๐Ÿ”ด AdvancedWrite-Heavy, Event-DrivenSaga, Circuit Breaker, DDD, Kafka

Released under the ISC License.