Distributed Systems

Table of Contents

A centralized system consists of major functions performed by a single physical computer. A distributed system, on the other hand, consists of physically separate machines working together on the same task. This could be multiple servers in the same room or building working together, or a peer-to-peer/widespread collaboration topology. Distributed systems promises higher availability with multiple machines, better durability since data is stored in multiple locations, and more security since each piece is easier to make secure.

However, reality has been disappointing at times. We see worse avilability since a distributed system ends up being dependent on every machine being up (“a distributed system is one in which the failure of a computer you didn’t even know existed can render your own computer unusable” — Leslie Lamport). It often has worse reliability, as the system could lose data if any machine crashes. Coordination is also generally more difficult, as we must coordinate multiple copies of shared state information. Security is an issue as well: can you trust the other members of a distributed application enough to even perform a protocol correctly?

1. Protocols

Distributed systems have to communicate, and they do so via communication protocols. The Internet, for example uses many protocols, but there is only one network-layer protocol: IP.

distributed1.png

This “narrow waist” facilitates interoperability:

  • allows arbitrary networks to communicate
  • allows applications to function on all networks
  • supports simultaneous innovations above and below IP

2. End-to-End Argument

“End-to-End Arguments in System Design” by Saltzer, Reed, and Clark (1984) was a hugely influential paper that proposed what is known as the end-to-end argument: that some types of network functionality can only be correctly implemented end-to-end.

Say we want to implement reliable file transfers. One way to do this is to make each step reliable, and then concatenate them. Another way to do this is to perform an end-to-end check and try again if necessary. The first way is incomplete: it is impossible to fully guarantee that our solution is perfect, and we still have to do the check anyway. The second way is complete: the full functionality can be entirely implemented at the application layer with no need for reliability from lower layers.

The end-to-end principle says that implementing complex functionality in the network:

  • doesn’t reduce host implementation complexity
  • does increase network complexity
  • probably imposes delay and overhead on all applications, even if they don’t need that functionality

If hosts can implement functionality correctly, implement it in a lower layer only as a performance enhancement, and that it doesn’t impose a burden on applications that do not require that functionality.

3. Distributed Decision Making

Distributed decision making is desirable as it is more fault tolerant. A groupt of machines can come to a decision even if one or more of them fail during the process.

3.1. General’s Paradox

Say we have two generals on separate mountains that can only communicate via messengers. Critically, however, these messengers can be captured. The two generals wish to coordinate an attack: if they attack at different times, they all die; if they attack at the same time, they win.

We can reframe this question as: can messages over an unreliable network be used to guarantee two entities do something simultaneously?

The answer is no, even if all messages get through. This is because there is no way to be sure last message gets through, since each message needs an acknowledgement!

3.2. Two-Phase Commit

Since we can’t solve the General’s Paradox (i.e. simultaneous action), let’s solve a relaxed problem. We want two or more machines to agree to do something (or not do it), atomically. There are no constraints on time here, just that it will eventually happen.

One solution is the two-phase commit protocol. We keep a persistent stable log on each machine, which keeps track of whether the commit has happened. If a machine crashes, it first checks its log on startup to recover state of the world at time of crash.

During the prepare phase, the coordinator asks all participants to either promise to commit or abort the transaction. The voters first record their promise in the log, then acknowledges their promise to the coordinator.

During the commit phase, if anyone votes to abort, thec coordinator writes abort in its log and tells everyone to abort; each records abort in their respective logs. On the other hand, if all participants vote to commit, then the coordinator writes commit to its log. Then the coordinator asks all nodes to commit; each node responds with ACK, and once coordinator receives all ACKs, the coordinator writes got commit to its log.

We can represent the two-phase commit protocol as a state machine:

However, there is an undesirable feature of two-phase commit, which is that it blocks if a node fails. One machine can be stalled until another site recovers. Alternatives to two-phase commit include:

  • Three-phase commit: one more phase that allows nodes to fail or block and still make progress
  • PAXOS: an alternative used by Google and others, however some believe it is extremely complex
  • RAFT: PAXOS alternative that is simpler to describe complete protocol

3.3. Byzantine General’s Problem

Say we have one general and \(n-1\) lieutenants (\(n\) players total). However, some number of these (including the general) can be malicious. The commanding general must send an order to his lieutenants such that the following integrity constraints apply:

  1. All loyal lieutenants obey the same order.
  2. If the commanding general is loyal, then all loyal lieutenants obey the order he sends.

It is impossible to solve the problem with \(n=3\) because one malicious player can mess up things. It can be seen that for a lieutenant in this configuration, it is impossible for it to distinguish if its fellow lieutenant is malicious or the general is malicious. It can also be shown that if we have \(f\) malicious entities, then we need \(n > 3f\) to solve the problem.

One solution is the Byzantine Fault Tolerance (BFT) algorithm, which allows multiple machines to make a coordinated decision even if some subset of them (\(< \frac{n}{3}\)) are malicious.

4. Remote Procedure Calls

Remote procedure call (RPC) is a way to call a procedure on a remote machine such that it looks like an ordinary function call. The idea is that the RPC service automates all the complexity of translating between representations of data on each side and communicating between machines. “Stubs” provide glue on the client/server, responsible for serializing and/or deserializing incoming or outgoing data. A stub generator is involved to generate these stubs, often from a interface definition language (IDL), which outputs source code in the appropriate language.

Note that RPC is not performance transparent: there is a lot of overhead involved with serialization, stubs, kernel-crossing, communication, etc. Programmers should be aware that RPC is not “free.”

5. Distributed File Systems

In a distributed file system, we want transparent access to files stored on a remote disk. To do this, we mount remote files onto our local file system, where a directory in the local file system resolves to remote files.

5.1. Virtual Filesystem Switch

The enabling architecture for this is the virtual filesystem switch, or VFS. VFS acts as an abstraction layer so that the operating system can interact with multiple different types of file systems at the same time:

distributed2.png

VFS allows the same syscall interface to be used for different types of file systems: in other words, the API is the VFS interface, rather than any specific type of file system. In VFS, there are four primary object types:

  • superblock: represents a specific mounted filesystem
  • inode: represents a specific file
  • dentry: represents a directory entry
  • file: represents an open file associated with process

Note that there is no specific directory object (it is just a file). Additionally, depending on the type of file system, you may need to fit the VFS model by “faking” the file system to make it look like it has inodes, blocks, etc.

5.2. Network File System

The Network File System (NFS) was developed by Sun Microsystems in 1984 as a distributed file system. It consists of three layers:

  • the UNIX filesystem interface: open, read, write, etc.
  • VFS layer: distinguishes local from remote files
  • NFS service layer: the bottom layer that implements the NFS protocol

The NFS protocol used RPC for file operations on server. It used the XDR serialization standard for data format independence. It also used write-through caching, which means that modified data was committed to the server’s disk before results are returned to the client.

NFS servers are stateless: each request provides all arguments required for execution. Requests are also idempotent: performing requests multiple times has the same effect as performing them exactly once. For example, doing a remove operation twice on the same file will yield only an advisory error on the second operation.

The NFS protocol has weak consistency when it comes to caches. It is up to the client to poll the server periodically to check for changes. Thus, when a file is changed by one client, the server is notified, but other clients have the old file until they timeout and check again.

5.3. Andrew File System

The Andrew File System (AFS) developed at Carnegie-Mellon and later folded into commercial products by IBM incorporates callbacks: the servre records who has a copy of each file. On changes, the server immediately tells all clients with the old copy, so clients don’t have to spend bandwidth on polling.

Changes by clients are also not propagated to the server until close() is called. Therefore, updates are visible to other clients only after the file is closed. As a result, you never get “partial writes.” Although for processes on the same machine, updates are immediately visible to other local programs.

5.4. Network-Attached Storage

The CAP theorem states that you cannot have consistency, availability, and partition-tolerance at the same time (otherwise known as Brewer’s theorem). Consistency means that changes appear to everyone in the same serial order. Availability means that a client can get a result at any time. Partition-tolerance means that the system continues to work even when the network becomes partitioned.

Last modified: 2026-12-01 14:52