Distributed Systems 101
What are Distributed Systems?
Distributed systems are the backbone of the scalable application and infrastructure tools we use today. When scaling a server, there are two major approaches: vertical and horizontal scaling. Vertical scaling is possible, but it is limited by how many resources can be added to an existing server. Distributed systems fall under horizontal scaling.
A Distributed System is a collection of independent computers working together, communicating over a network to achieve a goal. It gives the illusion of a single system to its users.
Why Distributed Systems?
- Performance: How fast can this task be done?
- Scalability: How much more can the system handle when more resources are added?
Expectations
- Reliability: Correctness of results
- Fault Tolerance: The system keeps functioning during failure
- Availability: The system is responsive
Achieving the above in a distributed system is complex. As a matter of fact, it is advised that if a problem can be solved using one system, it is better to keep it that way; designing and building distributed systems are difficult.
Decisions
Building a distributed system is all about making tradeoffs. You really can’t get it all. The foundation is to identify the important features in your system and prioritise them. Questions like: latency or throughput? strong, eventual, or weak consistency? What happens if one of the systems in the cluster goes down or doesn’t receive a message? There’s no definite answer to any of this; it depends on what you’re trying to achieve.
One thing that is almost certain is partial failure likely due to network issues (networks are unreliable), bad disks, power outages and many other causes. Although from a user’s point of view, the system still seems reliable, since it’s designed to keep functioning despite partitions. This is one of many reasons why distributed systems are difficult.
CAP Theorem
The trade-off is formally described by the Consistency, Availability and Partition Tolerance (CAP) theorem. It states a distributed system can only guarantee two of the three properties at once. In practice, partition tolerance isn’t optional because partitions are inevitable since networks are inherently unreliable. So the real choice usually comes down to consistency vs availability.
Requisites For Understanding Distributed systems
To understand and build a distributed system, it’s essential to have a grasp of computer science fundamentals such as operating systems, computer networking and concurrent programming. These lay the foundation for understanding terms like locks, deadlocks, TCP connections and many more.
Remote Procedure Call (RPC)
Once multiple machines need to communicate, RPC comes to the rescue. It adds a layer of abstraction to network communication, allowing a program to call a function as if it were a local function. That said, RPC only gives you the abstraction. It still fails in ways a local function never would. This is captured well in Peter Deutsch’s “Fallacies of Distributed Computing”, a list of assumptions people wrongly make about networks, such as “the network is reliable” or “latency is zero”, that breaks down once you’re actually distributed.
Abstraction for Developers
One of the aims of building a distributed system is to provide a level of abstraction for app developers. Much of the (usually complex) process that handles the underlying internal operations of a system is abstracted away from application developers, who are instead given access via an interface or API. This eases development and gives developers with no knowledge of the distributed system’s internals the ability to use it.
Conclusion
The above shows why distributed systems are hard. To get a feel for how decisions are made in building these systems, we will explore academic or industry papers, starting with the MapReduce paper in the next post. It is often readable and ties directly into the concepts discussed above.
Cheers!