Before designing complex microservice platforms or real-world apps (like Uber or Netflix), you must master the
core architectural building blocks and first principles. These concepts explain how distributed systems scale, handle network failures, and trade speed for consistency.
Scale Up (Vertical): Adding more RAM, CPU cores, or SSD storage to a single machine.
Trade-off: Simple, no network partitioning overhead, but hard hardware cost limits and single point of failure (SPOF).
Scale Out (Horizontal): Adding more server nodes in parallel behind a Load Balancer.
Trade-off: Infinite capacity scaling, high fault tolerance, but requires stateless app tier and distributed session storage.
Latency: The time required for a single operation to complete (measured in milliseconds, e.g., $15\text{ms}$ DB read).
Throughput: The number of operations processed per unit of time (measured in QPS or TPS).
First Principle: Optimizing throughput (e.g., message queue batching) often slightly increases latency for individual requests.
In any distributed data store during a network Partition (P), you can only choose one:
• CP (Consistency): Block or reject reads/writes to prevent returning stale data (e.g., PostgreSQL primary, HBase).
• AP (Availability): Return available data immediately, accepting that some replicas might be stale (e.g., Cassandra, DynamoDB).
Extends CAP theorem to describe normal operations when there is no partition:
If Partition (P): Choose Availability (A) or Consistency (C).
Else (E): Choose Latency (L) or Consistency (C).
Example: DynamoDB is PA/EL (fast latency under normal run), while MongoDB is PC/EC (strict consistency even during normal run).
Splitting a giant database table across multiple database nodes.
• Horizontal Partitioning (Sharding): Distributing table rows across shards using a Shard Key (e.g., user_id % N).
• Vertical Partitioning: Splitting columns across tables (e.g., User Profile vs User Billing Data).
Caching stores hot data in fast RAM (e.g., Redis) to prevent slow disk I/O.
• Cache-Aside: Application checks cache first; loads from DB on miss.
• Write-Through: Application writes to cache, which synchronously updates DB.
• Write-Back: Application writes to cache; cache asynchronously updates DB in background batches.