System Design Refresher
Scalability
Scalability is the ability of a system to handle increased load (users, data, or requests) without sacrificing performance or reliability.
Two main approaches:
Horizontal Scaling (Scale Out)
Add more machines/servers.
Example: Adding more web servers behind a load balancer when traffic spikes.
Vertical Scaling (Scale Up)
Add more power (CPU, RAM, storage) to a single machine.
Example: Upgrading your database server to a larger instance.
👉 Horizontal scaling is often preferred for distributed systems because it’s cost-effective and avoids single points of failure.
Sharding
Sharding is splitting a large database into smaller, more manageable chunks called shards. Each shard stores only a portion of the data.
How it works:
Users 1–1M → Shard A
Users 1M–2M → Shard B
Users 2M–3M → Shard C
Why it matters:
Avoids overwhelming a single database.
Improves read/write performance.
Enables scaling out databases horizontally.
Real-world example:
Twitter shards user data so that one database isn’t responsible for every tweet ever posted.
Replication
Replication means creating multiple copies of the same data across different servers.
Models:
Master-Slave:
Master handles writes.
Slaves handle reads.
Master-Master:
Multiple masters handle both reads/writes, syncing changes between them.
Benefits:
High availability (failover if one DB goes down).
Improved read performance (scale reads across replicas).
Data durability (extra copies).
Example:
MySQL replication powers many e-commerce platforms to ensure reads are fast and failover is automatic.
Partitioning
Partitioning is similar to sharding but usually refers to splitting data within a database (logical or physical divisions).
Types of Partitioning:
Horizontal Partitioning (Sharding) – Rows are divided across different databases/tables.
Vertical Partitioning – Columns are split into different databases/tables (e.g., separating user profile info from login credentials).
Benefits:
Reduces table size → faster queries.
Isolates workloads (analytics vs transactions).
Caching
Caching stores frequently accessed data in a faster, temporary storage layer (often memory). This reduces database load and improves response times.
Strategies:
Cache-aside (Lazy Loading): App checks cache → if miss, fetch from DB → update cache.
Write-through: Writes go to both cache + DB.
CDN (Content Delivery Network): Geographically distributed caches for static files (images, videos, CSS).
Why caching matters:
Faster responses.
Lower infrastructure costs (fewer DB hits).
Better user experience during high traffic.
Example:
Netflix caches video metadata at edge servers so users can browse instantly.