When Computers Must Cooperate Over Networks
In previous lessons, we added load balancers, scaled application clusters, replicated databases, deployed caches, and wired message queues.
Our system is no longer a single isolated server. It is now a Distributed System spanning dozens of independent compute nodes:
This introduces a fundamental architectural question:
“When 50 independent computers cooperate over network cables to deliver a single web application, how does the system maintain coherent state when cables sever, servers crash, or network packets vanish?”
Why Multiple Computers?
If a single computer could satisfy all operational requirements, no engineering team would voluntarily embrace distributed systems complexity. We distribute architectures for three core reasons:
A Network Call is NOT a Local Function Call
Calling a local function getUser() inside memory executes deterministically in nanoseconds. It never drops packets or experiences routing timeouts.
However, when Service A calls Service B over a network:
❌ Packets drop midway at intermediary routers
❌ Service B is stalling due to garbage collection pauses or thread pool exhaustion
❌ Service B successfully processes the charge, but the response packet drops on the return route!
⚠️ Service A faces ambiguity: Did the charge succeed, or did it fail?
“The Golden Rule of Distributed Systems: Failure is not an edge case; failure is the default environment. Architect systems assuming remote calls can and will fail at any moment.”
Consistency Models: Strong vs. Eventual Consistency
When data is replicated across multiple nodes, the rules governing when nodes agree on data state define the system's Consistency Model:
Every read request across any node is guaranteed to return the latest committed write. Stale reads are physically prevented.
✗ Penalty: Higher latency; blocks writes during network partitions.
Replicas do not synchronize immediately. Temporary read divergence is tolerated. Given sufficient time without new writes, all nodes eventually converge to the identical state.
✓ Advantage: Blazing speed and 100% availability.
The CAP Theorem: The Law of Distributed Nature
Formulated by Dr. Eric Brewer, the CAP Theorem proves that a distributed data store can guarantee at most two out of three properties simultaneously:
- C (Consistency): Every read receives the latest write or an error.
- A (Availability): Every non-failing node returns a response for every request (no errors, but may return stale data).
- P (Partition Tolerance): The system continues to operate despite arbitrary message loss or network partitions between nodes.
The Architectural Reality: P is Non-Negotiable!
In physical networks, hardware routers fail, switch cables disconnect, and datacenters lose cross-connects. You cannot simply "opt out" of network partitions.
Therefore, when a partition occurs, an architect must choose between CP and AP:
Distributed Transactions & The Saga Pattern
In a monolithic SQL database, transactions are simple: BEGIN ... COMMIT / ROLLBACK.
In microservices architectures where Orders, Payments, and Inventory live on discrete databases, traditional Two-Phase Commit (2PC) blocks threads and destroys performance.
The Saga Pattern: Orchestrated Compensating Actions
A Saga breaks a distributed transaction into a sequence of local transactions. Each step is paired with a Compensating Transaction (Rollback Action):
The Circuit Breaker: Preventing Cascading Failures
Just as electrical circuit breakers trip to protect residential appliances during power surges, software Circuit Breakers prevent failing dependencies from crashing calling services.
If an upstream recommendation service starts taking 10-second timeouts, calling it repeatedly exhausts caller connection pools and brings down the entire website (Cascading Collapse).
Interactive Distributed Systems Workbench
Simulate network partitions, circuit breaker state machines, and Saga rollbacks
Distributed Systems Quiz
Validate your comprehension of Lesson 11.8 core concepts
1. According to the CAP Theorem, when an unavoidable network partition disconnects two datacenters, what is an architect's only operational option?
2. When a Circuit Breaker enters the "Open" state, how does it behave upon receiving an incoming request?
3. In the Saga Pattern, what is the role of a "Compensating Transaction"?
Monolith, Modular Monolith & Microservices: How to Decompose an Application
Does every project really need microservices? Why do tech giants start with monoliths, and how does the golden middle ground of "Modular Monoliths" offer the best of both worlds?