Vertical vs. horizontal scaling, load balancing, caching, sharding, and much more

By The Coding Gopher

Published: 2026-06-23

URL: https://thecodinggopher.substack.com/p/the-8-most-important-system-design


The foundational principles and engineering trade-offs of distributed computing.

Redis: What It Is, What It Does, and Why You Should Care | Backendless \Redis is an open-source, in-memory data structure store used primarily as a high-performance database, cache, and message broker.\

The landscape of software engineering is constantly shifting. Frameworks evolve, and cloud providers release new managed services every week. However, the underlying physics of distributed systems remain the same. Whether you are building an internal dashboard or a global streaming platform, every architectural decision eventually boils down to how you handle state, network latency, and physical hardware limits.

Here is a deep dive into the 8 fundamental concepts that govern modern distributed system design.


1. Scalability: Vertical vs. Horizontal

When a system begins to buckle under the weight of increased traffic, it must scale. There are two entirely different paradigms for adding capacity, each with massive architectural implications.

Horizontal vs. Vertical Scaling: What's the Best Path for Your Business? | by Yasith Wimukthi | Stackademic

  • Vertical Scaling (Scaling Up): This involves adding more compute power to an existing machine (e.g., upgrading a database server from 64GB of RAM to 256GB).
  • The Engineering Reality: It requires zero code changes, but it has a strict physical and financial ceiling. More critically, it retains a single point of failure; if the hardware fails, the entire system goes offline.
  • Horizontal Scaling (Scaling Out): This involves adding more individual machines to a resource pool. Instead of one massive server, you provision ten standard servers to share the load.
  • The Engineering Reality: It provides virtually infinite scalability and inherent fault tolerance. However, it requires your application servers to be strictly stateless (they cannot store user session data locally), forcing you to manage distributed state in external caches or databases.

2. Load Balancing: Distributing Network Traffic

Once you scale horizontally, incoming network requests need a mechanism to determine which specific server to route to. This is solved by a Load Balancer, acting as a reverse proxy.

A reverse proxy is a server positioned in front of web servers that intercepts client requests (from browsers) and forwards them to the appropriate backend server. It acts as an intermediary for incoming traffic, enhancing security, performance, and reliability by hiding the internal network structure, load balancing traffic, and managing SSL encryption.

Understanding Load Balancers: Traffic Management at Scale

  • Layer 4 vs. Layer 7: A Layer 4 load balancer routes traffic based purely on network data (IP addresses and TCP ports)โ€”it is highly efficient. A Layer 7 load balancer inspects the actual application payload (HTTP headers, cookies) to make smarter routing decisions, but consumes more CPU.

Types of Load Balancing Algorithms (Animated + Code Examples) \Routing Algorithms.Load balancers use algorithms likeRound Robin(sequential distribution),Least Connections(sending traffic to the server with the fewest active requests), orIP Hashing(ensuring a specific user always hits the exact same server).\

  • Health Checking: Load balancers constantly ping the backend servers. If a server stops responding, it is instantly removed from the rotation, ensuring users are not routed to a dead node.

3. Caching: In-Memory Data Storage

The most effective way to improve system latency is to avoid doing the same computationally expensive work twice. Caching involves temporarily storing frequently accessed data in extremely fast, in-memory storage (like Redis or Memcached) rather than fetching it from a slower disk-based database.

How In-Memory Caching Works in Redis

  • Cache-Aside: The application checks the cache first. If the data is missing, it queries the database, saves the result to the cache, and then returns it to the user.

A Guide to Top Caching Strategies - ByteByteGo Newsletter

  • Write-Through vs. Write-Behind: In a write-through cache, data is written to the cache and the database simultaneously, ensuring perfect consistency but slowing down write speeds. In a write-behind cache, data is written only to the cache and asynchronously synced to the database later, offering fast writes but introducing the risk of data loss if the cache server crashes before the sync.

Caching Strategies Explained: Write-Through, Write-Back, and Cache-Aside | by Stoic Engineer | Medium

  • Eviction Policies: Because RAM is expensive and finite, caches use algorithms like LRU (Least Recently Used) or LFU (Least Frequently Used) to automatically delete old data when memory reaches capacity.

๐‹๐ž๐š๐ซ๐ง ๐ญ๐จ ๐›๐ฎ๐ข๐ฅ๐ ๐†๐ข๐ญ, ๐ƒ๐จ๐œ๐ค๐ž๐ซ, ๐‘๐ž๐๐ข๐ฌ, ๐‡๐“๐“๐ ๐ฌ๐ž๐ซ๐ฏ๐ž๐ซ๐ฌ, ๐š๐ง๐ ๐œ๐จ๐ฆ๐ฉ๐ข๐ฅ๐ž๐ซ๐ฌ, ๐Ÿ๐ซ๐จ๐ฆ ๐ฌ๐œ๐ซ๐š๐ญ๐œ๐ก. Get 40% OFF CodeCrafters: <https://app.codecrafters.io/join?via=the-coding-gopher>

This Substack is reader-supported. To receive new posts and support my work, consider becoming a free or paid subscriber.


4. Replication: Data Redundancy and Read Scaling

While scaling web servers is relatively straightforward, databases are persistent and stateful. To protect against data loss and handle high read volumes, databases use Replicationโ€”duplicating the exact same dataset across multiple physical nodes.

A Guide to Database Replication: Key Concepts and Strategies

  • Leader-Follower (Master-Slave): All write operations (INSERT, UPDATE) are routed to a single โ€œLeaderโ€ node to prevent data conflicts. The leader then asynchronously copies those changes to multiple โ€œFollowerโ€ nodes. All read operations (SELECT) are routed to the followers, effectively distributing the read load.

A Guide to Database Replication: Key Concepts and Strategies

  • Replication Lag: Because the data copy happens over a network, there is a latency delay (often milliseconds, sometimes seconds). This introduces Eventual Consistencyโ€”if a user updates their profile picture and instantly refreshes the page, their read request might hit a Follower node that hasnโ€™t received the update yet, serving them the outdated picture.

5. Partitioning (Sharding): Write Scaling

Replication solves read bottlenecks, but when a database receives more writes than a single hard driveโ€™s I/O can handle, the dataset itself must be partitioned.

What are the differences between horizontal and vertical partitioning in a database?

  • Horizontal Partitioning: You break massive tables into smaller segments (shards) and place each segment on a completely separate database server. Node A holds users A-M; Node B holds users N-Z.
  • The Trade-off: Sharding provides massive write throughput, but it breaks standard relational database features. If an operation requires a JOIN between a row on Node A and a row on Node B, the database cannot execute it natively. The application layer must query both servers independently and stitch the data together in memory.

6. Message Queues: Asynchronous Decoupling

In a synchronous system, if Service A calls Service B, and Service B is slow, Service A is blocked waiting for a response. To survive massive traffic spikes without dropping requests, systems must decouple these processes using Message Queues (like Apache Kafka, RabbitMQ, or AWS SQS).

System Design- Apache Kafka. Designing a log writing system likeโ€ฆ | by Vikas Taank | DevOps.dev \*Kafka architecture is a distributed, commit-log based system designed for high-throughput, real-time data streaming.

It uses producers to send messages to topics, brokers to store them in immutable, ordered partitions, and consumers to read from these partitions, typically grouped together for parallel processing and scalability.\*

  • Producer-Consumer Pattern: When a user uploads a video, the web server (Producer) doesnโ€™t process it. It drops a โ€œVideo Uploadedโ€ message into the queue and instantly responds โ€œSuccessโ€ to the user. A separate fleet of backend servers (Consumers) pulls messages from the queue and processes the heavy video encoding asynchronously.
  • Buffering: If traffic spikes significantly, the backend servers wonโ€™t crash. The message queue acts as a buffer, safely holding the backlog of tasks until the consumers have the capacity to process them.

This Substack is reader-supported. To receive new posts and support my work, consider becoming a free or paid subscriber.

Thanks for reading! This post is public so feel free to share it.