# Brendan Burns - Designing Distributed Systems (Highlights) ![rw-book-cover|256](https://learning.oreilly.com/library/view/designing-distributed-systems/9781491983638/ibis_generated_cover_thumbnail.jpg) ## Metadata **Cover**:: https://learning.oreilly.com/library/view/designing-distributed-systems/9781491983638/ibis_generated_cover_thumbnail.jpg **Source**:: #from/readwise **Zettel**:: #zettel/fleeting **Status**:: #x **Authors**:: [[Brendan Burns]] **Full Title**:: Designing Distributed Systems **Category**:: #books #readwise/books **Category Icon**:: 📚 **Highlighted**:: [[2021-02-28]] **Created**:: [[2022-09-26]] ## Highlights ### 1. Introduction - The engineering skills needed to build a reliable distributed system are significantly higher - Regardless, the need for reliable distributed systems only continues to grow. #### The Value of Patterns, Practices, and Components - the first value of patterns: they allow us to learn from the mistakes of others. - A Shared Language for Discussing Our Practice - Shared Components for Easy Reuse ### 2. The Sidecar Pattern ### I. Single-Node Patterns - In general, the goal of a container is to establish boundaries around specific resources ### 3. Ambassadors - resource isolation - an ambassador container brokers ### 4. Adapters ### 5. Replicated Load-Balanced Services - replicated load-balanced service. In such a service, every server is identical to every other server and all are capable of supporting traffic. - The pattern consists of a scalable number of servers with a load balancer in front of them. - Readiness Probes for Load Balancing - In contrast to replicated services, with sharded services, each replica, or shard, is only capable of serving a subset of all requests. ### II. Serving Patterns - the ambassador pattern, where an ambassador container brokers interactions between the application container and the rest of the world. - An Example Sidecar: Adding HTTPS to a Legacy Service - The application simply always connects to an instance of the service (e.g., MySQL) running on localhost. It is the responsibility of the service broker ambassador to introspect its environment and broker the appropriate connection - the adapter pattern. In the adapter pattern, the adapter container is used to modify the interface of the application container so that it conforms to some predefined interface that is expected of all applications. - a readiness probe determines when an application is ready to serve user requests. ### 6. Sharded Services - In contrast to replicated services, with sharded services, each replica, or shard, is only capable of serving a subset of all requests. A load-balancing node, or root, is responsible for examining each request and distributing each request to the appropriate shard or shards for processing. ### 7. Scatter/Gather - the scatter/gather pattern is a tree pattern with a root that distributes requests and leaves that process those requests. #c1 ### 8. Functions and Event-Driven Processing - The sidecar pattern is a single-node pattern made up of two containers. ... In addition to the application container, there is a sidecar container. The role of the sidecar is to augment and improve the application container, often without the application container’s knowledge. ... The root server then combines the various partial results together to form a single complete response to the request and then sends this request back out to the client. - The benefits of FaaS are primarily for the developer. It dramatically simplifies the distance from code to running service. - The sidecar pattern is a single-node pattern made up of two containers. ... In addition to the application container, there is a sidecar container. The role of the sidecar is to augment and improve the application container, often without the application container’s knowledge. ... The root server then combines the various partial results together to form a single complete response to the request and then sends this request back out to the client. - the code that is deployed is managed and scaled automatically - Functions are stateless and thus any system you build on top of functions is inherently more modular and decoupled than a similar system built into a single binary. - it is often quite difficult to obtain a comprehensive view of your service, determine how the various functions integrate with one another, and understand when things go wrong, and why they go wrong. - This means that FaaS is usually a poor fit for situations that require processing. - The first of these limitations is the need to have a significant amount of data loaded into memory in order to process user requests. - as a service grows, the number of requests that you are servicing grows to the point where you can keep a processor continuously active servicing user requests. At this point, the economics of a pay-per-request model start to become bad ### Patterns for FaaS ##### Determining When FaaS Makes Sense - The Decorator Pattern: Request or Response Transformation FaaS is ideal for deploying simple functions that can take an input, transform it into an output, and then pass it on to a different service. ### 9. Ownership Election - There are two ways to implement this master election. This first is to implement a distributed consensus algorithm like Paxos or RAFT, ... Fortunately, there are a large number of distributed key-value stores that have implemented such consensus algorithms for you. - Implementing Locks ... compareAndSwap(l.lockName, "1", "0", l.ttl) - Implementing Ownership ... we need to create a renewable lock, which can be periodically renewed by the owner so that the lock can be retained for an arbitrary period of time. - In a work queue system, there is a batch of work to be performed. Each piece of work is wholly independent of the other and can be processed without any interactions. - These sort of event-driven processing systems are often called workflow systems, since there is a flow of work through a directed, acyclic graph that describes the various stages and their coordination ### III. Batch Computational Patterns - The job of a copier is to take a single stream of work items and duplicate it out into two or more identical streams. - The role of a filter is to reduce a stream of work items to a smaller stream of work items by filtering out work items that don’t meet particular criteria ### 10. Work Queue Systems - The role of a splitter is to evaluate some criteria—just like a filter—but instead of eliminating input, the splitter sends different inputs to different queues based on that criteria. - the role of a sharder in a workflow is to divide up a single queue into an evenly divided collection of work items based upon some sort of sharding function. - When the number of healthy shards is reduced due to failures, the sharding algorithm dynamically adjusts to send work to the remaining healthy work queues ### 11. Event-Driven Batch Processing - the job of a merger is to take two different work queues and turn them into a single work queue. - pull multiple outputs back together in order to generate some sort of aggregate output. - There are two ways to implement this master election. This first is to implement a distributed consensus algorithm like Paxos or RAFT, ... Fortunately, there are a large number of distributed key-value stores that have implemented such consensus algorithms for you. - Implementing Locks ... compareAndSwap(l.lockName, "1", "0", l.ttl) - Implementing Ownership ... we need to create a renewable lock, which can be periodically renewed by the owner so that the lock can be retained for an arbitrary period of time. ### 12. Coordinated Batch Processing