Database Design
AI Take..
System Design Pathway: From 0 to "Can design Twitter/YouTube"
Think of it like building a house. You don't start laying bricks. You start with: "How many people live here?"
Here’s the full step-by-step framework FAANG + startups use:
THE 6-STEP SYSTEM DESIGN FRAMEWORK
STEP 1: REQUIREMENTS CLARIFICATION - "What are we building?"
Goal: Don't build the wrong thing
- Functional Requirements: What must the system DO?
Bad: "Build YouTube"
Good: "Users can upload, watch, search, comment, like videos" - Non-Functional Requirements: How well must it work?
Scale: 1M DAU? 1B DAU?
Latency: <200ms?
Consistency: Can comments be 2s delayed? - Out of Scope: What are we NOT building?
V1: No live streaming. No 4K.
Rule: Spend 5-10 min here. Ask tons of questions.
STEP 2: HIGH LEVEL DESIGN / BACK OF ENVELOPE - "Big boxes"
Goal: Draw the main components
[Users] -> [Load Balancer] -> [API Servers] -> [App Logic]
-> [Cache: Redis]
-> [Database: Postgres]
-> [Object Storage: S3 for videos]
-> [CDN: Cloudflare]
-> [Queue: Kafka for processing]
Ask: Stateless? Where is data stored? What talks to what?
STEP 3: DATABASE DESIGN - "How do we store data?"
This is what you asked about 👇
- Entities: User, Video, Comment, Like
- Tables + Schema:
users(id, name, created_at)
videos(id, user_id, url, views)
comments(id, video_id, user_id, text) - Relationships: 1 User - Many Videos
- Scale: 1B videos? Partition by
video_id. Add read replicas. - Indexes: Index
videos.user_idfor "get my uploads"
STEP 4: DETAILED COMPONENT DESIGN - "Zoom into 1 box"
Pick the hardest part and design it deep.
Examples:
- News Feed: How to generate feed? Pull vs Push model?
- Upload: How to handle 4GB video? Chunk upload + async encoding
- Search: ElasticSearch vs DB LIKE query?
- Rate Limiting: Token bucket in Redis
Draw sequence diagrams. User -> API -> Cache miss -> DB -> Cache set -> Return
STEP 5: SCALE + BOTTLENECKS - "What breaks at 10M users?"
Go through each component and ask "What fails first?"
- DB: Too many writes → Sharding, Replication
- API: Too many requests → Auto-scaling, More servers
- Storage: Too expensive → CDN, Compression
- Single Point of Failure: 1 DB → Master-Slave, Multi-region
STEP 6: JUSTIFY + TRADEOFFS - "Why not Kafka?"
The interviewer will poke holes.
Q: "Why SQL and not Mongo?"
A: "We need transactions for payments. Mongo is eventually consistent"
YOUR LEARNING PATHWAY: 8 WEEKS TO GET GOOD
Week | Focus | Practice
1-2 | Fundamentals | Learn: Load Balancer, Cache, DB, CDN, Queue, CAP Theorem. Build 1 tiny system
3-4 | Database + Scaling | Normalization, Indexing, Sharding, Replication. Design: Instagram DB
5-6 | Core Patterns | Practice 10 classic systems: URL Shortener, Rate Limiter, Chat, Feed, YT, Uber
7 | Advanced | Consistent Hashing, Distributed Transactions, Microservices vs Monolith
8 | Mock Interviews | Time yourself: 45min per design. Explain out loud
3 RULES THAT WILL SAVE YOU
- Always start with scale: "How many users?" changes everything. 1k users = 1 server. 1B users = 1000 servers
- Draw first, talk second: 1 diagram > 1000 words. Use boxes + arrows
- Say your tradeoffs: "Redis is fast but we lose data on crash. So we also write to DB"
Free resources to start today
- Book: "System Design Interview Vol 1 & 2" by Alex Xu
- YouTube: Gaurav Sen, NeetCode System Design
- Practice:
systemdesign.one- has diagrams for all big tech systems
Want me to run you through a full example using this 6-step framework?
Pick 1:
- URL Shortener like http://bit.ly - Easiest to start
- eFootball Stats Tracker - Based on your other questions
- SaaS App for your startup - Most relevant to you
Which one should we design together step by step?