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 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.

- 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.

- 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.
\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.

- 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.

- 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.

- 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.

- 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.

- 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.
- 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
JOINbetween 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).
\*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.