# Patterns of Distributed Systems ![rw-book-cover](https://m.media-amazon.com/images/I/71o4a1A22PL._SY160.jpg) ## Metadata - Author: [[Unmesh Joshi]] - Full Title: Patterns of Distributed Systems - Category: #java #multi-threading ## Highlights - when the CPU or memory limit is reached, requests must wait for their turn to be processed. When these physical limits are pushed to their capacity, this results in queuing. As more requests pile up, waiting times increase, negatively impacting the server’s ability to efficiently handle user requests. ([Location 382](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=382)) - A common approach is to separate an architecture into two parts. The first part is the stateless component responsible for exposing functionality to end users. ([Location 392](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=392)) - commonly, a web API that serves user-facing applications. The second part is the stateful component, which is managed by a database ([Location 393](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=393)) - Replication plays a crucial role in masking failures and ensuring service availability. If data is replicated on multiple machines, even in the event of failures, clients can connect to a server that holds a copy of the data. ([Location 442](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=442)) - The TCP/IP network protocol operates asynchronously, meaning it does not provide a guaranteed upper bound on message delivery delay. This poses a challenge for software processes that communicate over TCP/IP. They must determine how long to wait for responses from other processes. ([Location 452](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=452)) - During the execution of a process, it can pause at any given moment. In garbage-collected languages like Java, execution can be interrupted by garbage collection pauses. In extreme cases, these pauses can last tens of seconds. ([Location 457](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=457)) - A distributed system is a software architecture that consists of multiple interconnected nodes or servers working together to achieve a common goal. These nodes communicate with each other over a network and coordinate their actions to provide a unified and scalable computing environment. ([Location 472](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=472)) - A pattern, by definition, is a “recurring solution” to a problem within a specific context. ([Location 485](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=485)) - An effective solution to this is Write-Ahead Log (Figure 2.4). With this, the message handler first writes all the information about the required update to a log file. This is a single write, so is simple to ensure it’s done atomically. Once the write is done, the handler can acknowledge to its caller that it has handled the request. Then the handler, or other component, can read the log entry and carry out the updates to the underlying files. ([Location 526](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=526)) - Databases use a Write-Ahead Log, as discussed in the above example, to implement transactions. ([Location 539](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=539)) - Nodes need a way to find out when connections to their colleagues break. They do this with a HeartBeat—or, more strictly, with the absence of a heartbeat. ([Location 561](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=561)) - If Neptune writes changes into a Write-Ahead Log and treats replication as copying those log entries to its followers, then its followers will be able to figure out what the correct state is by examining the log entries ([Location 576](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=576)) - To solve this kind of situation, we use a Generation Clock. This is a number that increments with each leadership election. It is a key requirement of Leader and Followers. ([Location 598](https://readwise.io/to_kindle?action=open&asin=B0CCD3F8BH&location=598))