Why This Book
In 2017, I was involved in developing a software system for a large optical telescope called Thirty Meter Telescope (TMT). We needed to build a core framework and services to be used by various subsystems. The subsystem components had to discover each other and detect component failures. There was also a requirement to store metadata about these components. The service responsible for storing this information had to be fault-tolerant. We couldn’t use off-the-shelf products and frameworks due to the unique nature of the telescope ecosystem. We had to build it all from scratch—to create a core framework and services that different subsystems of the software could use. In essence, we had to build a distributed system.
I had designed and architected enterprise systems using products such as Kafka, Cassandra, and MongoDB or cloud services from providers like AWS and GCP. All these products and services are distributed and solve similar problems. For the TMT system, we had to build a solution ourselves. To compare and validate our implementation choices with these proven products, we needed a deeper understanding of the inner workings of some of these products. We had to figure out how all these cloud services and products are built and why they are built that way. Their own documentation often proved too product-specific for that.
Information about how distributed systems are built is scattered across various research papers and doctoral theses. However, these academic sources have their limitations too. They tend to focus on specific aspects, often making only passing references to related topics. For instance, consider a well-written thesis, Consensus: Bridging Theory and Practice [ Ongaro2014 ]. It thoroughly explains how to implement the Raft consensus algorithm. But you won’t know how Raft is used by products like etcd for tracking group membership and related metadata for other products, such as Kubernetes. Leslie Lamport’s famous paper “Time, Clocks, and the Ordering of Events in a Distributed System” [ Lamport1978 ] talks about how to use logical clocks—but you won’t know how products like MongoDB use them as a version for the data they store.
I believe that writing code is the best way to test your understanding. Martin Fowler often says, “Code is like the mathematics of our profession. It’s where we have to remove the ambiguity.” So, to get a deeper understanding of the building blocks of distributed systems, I decided to build miniature versions of these products myself. I started by building a toy version of Kafka. Once I had a reasonable version, I used it to discuss some of the concepts of distributed systems. That worked well. To verify that explaining concepts through code works effectively, I conducted a few workshops within my company, Thoughtworks. Those turned out to be very useful. So I extended this to products like Cassandra, Kubernetes, Akka, Hazelcast, MongoDB, YugabyteDB, CockroachDB, TiKV, and Docker Swarm. I extracted code snippets to understand the building blocks of these products. Not surprisingly, there were a lot of similarities in these building blocks. I happened to discuss this with Martin Fowler a few years back, and he suggested writing about these as patterns. This book is the outcome of my work with Martin to document these common building blocks of distributed system implementations as patterns.
Who This Book Is For
Software architects and developers today face a plethora of choices when it comes to selecting products and cloud services that are distributed by design. These products and services claim to make certain implementation choices. Understanding these choices intuitively can be challenging. Just reading through the documentation is not enough. Consider sentences like “AWS MemoryDB ensures durability with a replicated transactional log” or “Apache Kafka operates independently from ZooKeeper” or “Google Spanner provides external consistency with accurate timing maintained by TrueTime.” How do you interpret these?
To get better insights, professionals rely on certifications from product providers. But most certifications are very product-specific. They focus only on the surface features of the product but not the underlying technical principles. Professional developers need to have an intuitive understanding of technical details that are specific enough to be expressed at the source-code level but generic enough to apply to a wide range of situations. Patterns help there. Patterns in this book will enable working professionals to have a good idea of what’s happening under the hood of various products and services and thus make informed and effective choices.
I expect most readers of this book to be in this group. In addition to those who work with existing distributed systems, however, there is another group of readers who must build their own distributed systems. I hope the patterns in this book will give that other group a head start. There are numerous references to design alternatives used by various products, which might be useful to these readers.
A Note on Examples
I have provided code examples for most of the patterns. The code examples are based on my own miniature implementations of the various products I studied while working through these patterns. My choice of language is based on what I think most readers are likely to be able to read and understand. Java is a good choice here. The code examples use a minimum of Java language features—mostly methods and classes, which are available in most programming languages. Readers familiar with other programming languages should be able to easily understand these code examples. This book, however, is not intended to be specific for any particular software platform. Once you understand the code examples, you will find similarities in code bases in C++, Rust, Go, Scala, or Zig. My hope is that, once you are familiar with the code examples and the patterns, you will find it easier to navigate the source code of various open-source products.
How to Read This Book
The book has six numbered parts that are divided into two main conceptual sections.
First, a number of narrative chapters cover the essential topics in distributed systems design. These chapters (in Part I ) present challenges in distributed system design along with their solutions. However, they don’t go into much detail on these solutions.
Detailed solutions, structured as patterns, are provided in the second section of the book ( Parts II to VI ). The patterns fall into four main categories: replication, partitioning, cluster management, and network communication. Each of these is a key building block of a distributed system.
Consider these patterns as references; there’s no need to read them cover to cover. You may read the narrative chapters for an overview of the book’s scope, and then explore the patterns based on your interests and requirements.
For additional reference materials, visit [https://martinfowler.com/articles/patterns-of-distributed-systems](https://martinfowler.com/articles/patterns-of-distributed-systems) .
I hope these patterns will assist fellow software professionals in making informed decisions in their daily work.
Register your copy of Patterns of Distributed Systems on the InformIT site for convenient access to updates and/or corrections as they become available. To start the registration process, go to [informit.com/register](http://informit.com/register) and log in or create an account. Enter the product ISBN (9780138221980) and click Submit. Look on the Registered Products tab for an Access Bonus Content link next to this product, and follow that link to access any available bonus materials. If you would like to be notified of exclusive offers on new editions and updates, please check the box to receive email from us.