Core Building Blocks — 12 Fundamental Concepts (Part 6)

The 12 Concept are :
Requirements Clarification (Part 1)
Back-of-Envelope Estimation (Part 1)
Databases — SQL vs NoSQL (Part 2)
Caching (Part 2)
Load Balancing (Part 3)
API Design (Part 3)
Message Queues + Event-Driven Systems (Part 4)
Consistency vs Availability (CAP Theorem) (Part 4)
Scaling Strategies (Part 5)
Fault Tolerance + Reliability (Part 5)
.CDN (Content Delivery Network) (Part 6)
Data Partitioning (Sharding) (Part 6)
But in this article we cover only two concept
11. CDN (Content Delivery Network)
What it is: A globally distributed network of servers that cache content close to users.
WHY it exists: Network latency increases with physical distance. A CDN in Singapore serves Singapore users faster than a server in Virginia.
What to put on CDN:
Static assets (JS, CSS, images)
Video content
Large downloadable files
What NOT to put on CDN:
Personalized dynamic content
Real-time data
Private user data (security risk)
Push vs Pull CDN:
Push: You upload content to CDN proactively. Good for known, large files.
Pull: CDN fetches from origin on first miss, caches for subsequent requests. Good for unpredictable access.
12. Data Partitioning (Sharding)
What it is: Splitting a large dataset across multiple database nodes.
WHY it exists: A single DB node has limited storage and throughput. Sharding breaks that limit.
Sharding strategies:
| Strategy | How | Good | Bad |
|---|---|---|---|
| Range-based | Shard by value range (A-M, N-Z) | Simple | Hot spots if distribution is skewed |
| Hash-based | Hash(key) % num_shards | Even distribution | Range queries become scatter-gather |
| Directory-based | Lookup table maps key to shard | Flexible | Lookup table is a bottleneck |
Shard key selection rule: The key should distribute data evenly AND be present in most queries.
Problems with sharding:
Cross-shard joins are very hard
Cross-shard transactions even harder
Resharding (adding shards) is painful
Beginner mistake: Choosing user_id as shard key when most queries are by timestamp. Your shard key must match your query patterns.



