From Code to Blueprint
Thinking in Systems, Not Just Code
System design is the process of defining the architecture, components, modules, interfaces, and data for a system to satisfy specified requirements.
It's the high-level blueprint for how we build scalable, reliable, and maintainable applications.
A structured approach is crucial. We will use this framework for any design problem.
The Architect's Toolkit
All the components we will discuss are tools for effective horizontal scaling.
A load balancer is a server that sits in front of your application servers and distributes incoming traffic across them.
Key Benefits:
A single database is often the first bottleneck.
The most important tool for improving read performance. We place a high-speed in-memory cache (like Redis) in front of our database.
By serving frequent requests from the cache, we dramatically reduce database load and improve latency.
A CDN is a geographically distributed network of proxy servers and their data centers.
It is a cache for your static assets (images, videos, JS/CSS files). It serves these assets from a server that is geographically close to the user, dramatically reducing latency.
The Fundamental Trade-off of Distributed Systems
The CAP Theorem states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees:
In a modern distributed system, network partitions (P) are a fact of life. You must assume they will happen. Therefore, the real trade-off is between Consistency and Availability.
As an architect, you must decide which guarantee is more important for your specific feature.
Applying the Framework
Assume 100 million new URLs per month. What are the read and write loads?
The system is read-heavy. This is a critical insight.
A single server and a single database.
Write Flow: `POST /shorten` with a long URL. The app generates a unique hash, stores `(hash, longURL)` in the database, and returns the short URL.
Read Flow: `GET /
This has single points of failure and will not scale.
Let's add our scaling components.
Your task is to work through the 4-step framework to design the backend for a simplified social media feed. We will do this together on the chalkboard.