Article

Understanding Core System Design Concepts

DKDhaval Kurkutiya
6 min read
Understanding Core System Design Concepts

System design is the process of defining the architecture, components, modules, interfaces, and data for a system to satisfy specified requirements. Whether you are building a small personal project or a massive web application handling millions of requests per second, understanding these core concepts is vital to creating scalable, reliable, and maintainable systems.

In this guide, we will explore the fundamental building blocks of system design.


1. Horizontal vs. Vertical Scaling

When traffic to your application increases, you need to expand your system's capacity. There are two primary scaling strategies: Vertical Scaling (Scale-Up) and Horizontal Scaling (Scale-Out).

MetricVertical Scaling (Scale-Up)Horizontal Scaling (Scale-Out)
DefinitionAdding more power (CPU, RAM, SSD) to an existing single server.Adding more physical or virtual servers to your pool.
ComplexityExtremely simple; no code or architectural changes required.Higher complexity; requires load balancing and state management.
LimitHard hardware limit (you can only buy a machine so large).Practically infinite scale (just keep adding cheap servers).
Fault ToleranceSingle point of failure (if the server crashes, the site goes down).High availability (if one server dies, others handle the traffic).
Cost CurveBecomes exponentially expensive at high-end specifications.Linear cost curve; leverages cost-efficient commodity hardware.

2. Load Balancers

As you adopt horizontal scaling and spin up multiple application servers, you need a mechanism to distribute incoming user requests evenly across those servers. This is where Load Balancers (LBs) come in.

A Load Balancer acts as a traffic cop sitting in front of your servers, routing client requests to the server best suited to handle them. This prevents any single server from becoming overloaded, improving response times and ensuring high availability.

Popular Load Balancing Algorithms:

  • Round Robin: Requests are distributed sequentially down the list of servers.
  • Least Connections: Directs traffic to the server with the active connections count. Good for long-running requests.
  • IP Hash: The client's IP address determines which server receives the request, ensuring that a specific user consistently routes to the same server (sticky sessions).

3. Caching & The Cache-Aside Pattern

Reading data from physical databases (like PostgreSQL or MySQL) requires disk I/O operations, which are slow and expensive. To speed up read times and relieve database load, we store frequently requested data in an ultra-fast, in-memory storage layer called a Cache (e.g., Redis or Memcached).

One of the most popular caching strategies is the Cache-Aside Pattern. In this pattern, the application queries the cache first. If the data is found (a cache hit), it is returned immediately. If not found (a cache miss), the application reads it from the database, writes it back into the cache for future requests, and then returns it.

Code Example: Cache-Aside Pattern (Node.js)

code
async function getUserProfile(userId) {
  const cacheKey = `user:${userId}`;
 
  // 1. Try fetching from Redis cache
  const cachedData = await redisClient.get(cacheKey);
  if (cachedData) {
    console.log("Cache Hit!");
    return JSON.parse(cachedData);
  }
 
  // 2. Cache Miss - Fetch from database
  console.log("Cache Miss! Querying SQL database...");
  const userProfile = await db.query(
    "SELECT id, name, email FROM users WHERE id = $1", 
    [userId]
  );
 
  if (!userProfile) return null;
 
  // 3. Write data back to cache with a 1-hour expiration (TTL)
  await redisClient.setEx(
    cacheKey, 
    3600, 
    JSON.stringify(userProfile)
  );
 
  return userProfile;
}

4. Content Delivery Networks (CDNs)

A Content Delivery Network (CDN) is a globally distributed network of proxy servers deployed in multiple data centers. Its primary purpose is to serve static assets (such as images, videos, HTML, CSS, and JavaScript files) to users from the geographical location closest to them (referred to as an Edge Server).

Why use a CDN?

  1. Reduced Latency: If your server is in Virginia and a user is in Mumbai, loading files from Virginia takes time. A CDN caches files in a Mumbai edge server, dropping latency from hundreds of milliseconds to single digits.
  2. Reduced Server Load: By offloading static file delivery to the CDN, your primary application servers can focus entirely on executing business logic.

5. SQL vs. NoSQL Databases

Choosing the right database is one of the most critical decisions in system design. Databases are broadly categorized into Relational (SQL) and Non-Relational (NoSQL).

FeatureRelational (SQL)Non-Relational (NoSQL)
SchemaRigid, predefined tabular schema.Flexible, dynamic schemas (documents, key-value, graphs).
ScalingTypically scales vertically (scale-up).Designed to scale horizontally (scale-out) out of the box.
TransactionsStrong ACID (Atomicity, Consistency, Isolation, Durability) guarantees.Focuses on BASE properties (Eventual Consistency, High Availability).
Best Used ForFinancial transactions, e-commerce orders, user profiles.Social feeds, real-time analytics, dynamic catalogs.
TechnologiesPostgreSQL, MySQL, SQLite, MS SQL.MongoDB, Cassandra, DynamoDB, Neo4j.

6. Message Queues & Event-Driven Architecture

In a monolithic system, components talk directly to one another. But in modern distributed systems, we want services to be decoupled. Message Queues (MQs) (like Apache Kafka or RabbitMQ) act as a buffer, allowing services to send and receive messages asynchronously.

When a user places an order on an e-commerce website:

  1. The Order Service writes the order to the database and immediately pushes an "Order Placed" event to the Message Queue.
  2. The user receives an instant "Order Received" response on their screen (sub-100ms latency).
  3. In the background, the Notification Service, Inventory Service, and Payment Service consume the event from the queue at their own pace to process the email alerts, deduct stock, and charge the credit card.

This ensures that even if the Notification Service goes down, the client can still place orders without facing error messages.


Conclusion

Building scalable systems is an iterative process. You don't build a system to handle 100 million users on day one. You start with a single server, add a database, introduce caching as reads slow down, add a load balancer to scale horizontally, and introduce queues to handle heavy async processing.

Understanding these individual components gives you the toolkit to solve almost any scaling problem that comes your way.