Foundations of Scalable Systems
{"all_nodes":"stitched from OCR output; frontier verification status per node"}local graph
Foundations of Scalable Systems — Ian Gorton
Section titled “Foundations of Scalable Systems — Ian Gorton”chapter_01
Section titled “chapter_01”node-book_foundations-of-scalable-systems_chapter-01-introduction-to-scalable-systems — Introduction to Scalable Systems
chapter_02
Section titled “chapter_02”node-book_foundations-of-scalable-systems_chapter-02-distributed-systems-architectures-an-introduction — Distributed Systems Architectures: An Introduction
chapter_03
Section titled “chapter_03”node-book_foundations-of-scalable-systems_chapter-03-distributed-systems-essentials — Distributed Systems Essentials
chapter_04
Section titled “chapter_04”node-book_foundations-of-scalable-systems_chapter-04-an-overview-of-concurrent-systems — An Overview of Concurrent Systems
chapter_05
Section titled “chapter_05”node-book_foundations-of-scalable-systems_chapter-05-application-services — Application Services
chapter_06
Section titled “chapter_06”node-book_foundations-of-scalable-systems_chapter-06-distributed-caching — Distributed Caching
chapter_07
Section titled “chapter_07”node-book_foundations-of-scalable-systems_chapter-07-asynchronous-messaging — Asynchronous Messaging
chapter_08
Section titled “chapter_08”node-book_foundations-of-scalable-systems_chapter-08-serverless-processing-systems — Serverless Processing Systems
chapter_09
Section titled “chapter_09”node-book_foundations-of-scalable-systems_chapter-09-microservices — Microservices
chapter_10
Section titled “chapter_10”node-book_foundations-of-scalable-systems_chapter-10-scalable-database-fundamentals — Scalable Database Fundamentals
chapter_11
Section titled “chapter_11”node-book_foundations-of-scalable-systems_chapter-11-eventual-consistency — Eventual Consistency
chapter_12
Section titled “chapter_12”node-book_foundations-of-scalable-systems_chapter-12-strong-consistency — Strong Consistency
chapter_13
Section titled “chapter_13”node-book_foundations-of-scalable-systems_chapter-13-distributed-database-implementations — Distributed Database Implementations
chapter_14
Section titled “chapter_14”node-book_foundations-of-scalable-systems_chapter-14-scalable-event-driven-processing — Scalable Event-Driven Processing
chapter_15
Section titled “chapter_15”node-book_foundations-of-scalable-systems_chapter-15-stream-processing-systems — Stream Processing Systems
chapter_16
Section titled “chapter_16”node-book_foundations-of-scalable-systems_chapter-16-final-tips-for-success — Final Tips for Success
Title page visual conversion
Section titled “Title page visual conversion”[!visual-conversion] Cover, PDF 001. The text is transcribed in full under “Title Page” below. The rest of the cover is decorative: the O’REILLY logo at the top and an engraving of a spotted fish below the subtitle, the series cover animal. The engraving carries no information the text needs, so no raster is embedded.
Title Page
Section titled “Title Page”O’REILLY
Foundations of Scalable Systems
Designing Distributed Architectures
Ian Gorton
Foundations of Scalable Systems
by Ian Gorton
Copyright © 2022 Ian Gorton. All rights reserved.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or [email protected].
| Acquisitions Editor: Melissa Duffield | Indexer: nSight, Inc. |
| Development Editor: Virginia Wilson | Interior Designer: David Futato |
| Production Editor: Jonathon Owen | Cover Designer: Karen Montgomery |
| Copyeditor: Justin Billing | Illustrator: Kate Dullea |
| Proofreader: nSight, Inc. |
July 2022: First Edition
Revision History for the First Edition
2022-06-29: First Release
2023-03-17: Second Release
See https://oreil.ly/scal-sys for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Foundations of Scalable Systems, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc.
The views expressed in this work are those of the author, and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-098-10606-5
[LSI]
Table of Contents
Section titled “Table of Contents”Table of Contents
Section titled “Table of Contents”- Preface — xi
Part I. The Basics
- 1. Introduction to Scalable Systems — 3
- What Is Scalability? — 3
- Examples of System Scale in the Early 2000s — 6
- How Did We Get Here? A Brief History of System Growth — 7
- Scalability Basic Design Principles — 9
- Scalability and Costs — 11
- Scalability and Architecture Trade-Offs — 13
- Performance — 13
- Availability — 14
- Security — 15
- Manageability — 16
- Summary and Further Reading — 17
- 2. Distributed Systems Architectures: An Introduction — 19
- Basic System Architecture — 19
- Scale Out — 21
- Scaling the Database with Caching — 23
- Distributing the Database — 25
- Multiple Processing Tiers — 27
- Increasing Responsiveness — 30
- Systems and Hardware Scalability — 32
- Summary and Further Reading — 34
- 3. Distributed Systems Essentials — 35
- Communications Basics — 35
- Communications Hardware — 36
- Communications Software — 39
- Remote Method Invocation — 43
- Partial Failures — 49
- Consensus in Distributed Systems — 53
- Time in Distributed Systems — 56
- Summary and Further Reading — 58
- Communications Basics — 35
- 4. An Overview of Concurrent Systems — 61
- Why Concurrency? — 62
- Threads — 64
- Order of Thread Execution — 67
- Problems with Threads — 68
- Race Conditions — 69
- Deadlocks — 73
- Thread States — 78
- Thread Coordination — 79
- Thread Pools — 82
- Barrier Synchronization — 84
- Thread-Safe Collections — 86
- Summary and Further Reading — 88
Part II. Scalable Systems
- 5. Application Services — 93
- Service Design — 93
- Application Programming Interface (API) — 94
- Designing Services — 97
- State Management — 100
- Applications Servers — 103
- Horizontal Scaling — 106
- Load Balancing — 107
- Load Distribution Policies — 109
- Health Monitoring — 109
- Elasticity — 110
- Session Affinity — 111
- Summary and Further Reading — 113
- Service Design — 93
- 6. Distributed Caching — 115
- Application Caching — 115
- Web Caching — 120
- Cache-Control — 121
- Expires and Last-Modified — 121
- Etag — 122
- Summary and Further Reading — 124
- 7. Asynchronous Messaging — 127
- Introduction to Messaging — 128
- Messaging Primitives — 128
- Message Persistence — 130
- Publish–Subscribe — 131
- Message Replication — 132
- Example: RabbitMQ — 133
- Messages, Exchanges, and Queues — 133
- Distribution and Concurrency — 135
- Data Safety and Performance Trade-offs — 138
- Availability and Performance Trade-Offs — 140
- Messaging Patterns — 141
- Competing Consumers — 141
- Exactly-Once Processing — 142
- Poison Messages — 143
- Summary and Further Reading — 144
- Introduction to Messaging — 128
- 8. Serverless Processing Systems — 147
- The Attractions of Serverless — 147
- Google App Engine — 149
- The Basics — 149
- GAE Standard Environment — 150
- Autoscaling — 151
- AWS Lambda — 152
- Lambda Function Life Cycle — 153
- Execution Considerations — 154
- Scalability — 155
- Case Study: Balancing Throughput and Costs — 157
- Choosing Parameter Values — 158
- GAE Autoscaling Parameter Study Design — 159
- Results — 160
- Summary and Further Reading — 161
- 9. Microservices — 163
- The Movement to Microservices — 164
- Monolithic Applications — 164
- Breaking Up the Monolith — 166
- Deploying Microservices — 168
- Principles of Microservices — 170
- Resilience in Microservices — 172
- Cascading Failures — 173
- Bulkhead Pattern — 178
- Summary and Further Reading — 180
- The Movement to Microservices — 164
Part III. Scalable Distributed Databases
- 10. Scalable Database Fundamentals — 185
- Distributed Databases — 185
- Scaling Relational Databases — 186
- Scaling Up — 186
- Scaling Out: Read Replicas — 188
- Scale Out: Partitioning Data — 189
- Example: Oracle RAC — 191
- The Movement to NoSQL — 192
- NoSQL Data Models — 196
- Query Languages — 197
- Data Distribution — 198
- The CAP Theorem — 202
- Summary and Further Reading — 203
- 11. Eventual Consistency — 205
- What Is Eventual Consistency? — 205
- Inconsistency Window — 206
- Read Your Own Writes — 207
- Tunable Consistency — 209
- Quorum Reads and Writes — 211
- Replica Repair — 213
- Active Repair — 214
- Passive Repair — 214
- Handling Conflicts — 215
- Last Writer Wins — 216
- Version Vectors — 217
- Summary and Further Reading — 221
- What Is Eventual Consistency? — 205
- 12. Strong Consistency — 223
- Introduction to Strong Consistency — 224
- Consistency Models — 226
- Distributed Transactions — 227
- Two-Phase Commit — 228
- 2PC Failure Modes — 230
- Distributed Consensus Algorithms — 232
- Raft — 234
- Leader Election — 236
- Strong Consistency in Practice — 238
- VoltDB — 238
- Google Cloud Spanner — 241
- Summary and Further Reading — 244
- 13. Distributed Database Implementations — 247
- Redis — 248
- Data Model and API — 248
- Distribution and Replication — 250
- Strengths and Weaknesses — 251
- MongoDB — 253
- Data Model and API — 254
- Distribution and Replication — 256
- Strengths and Weaknesses — 259
- Amazon DynamoDB — 260
- Data Model and API — 261
- Distribution and Replication — 264
- Strengths and Weaknesses — 266
- Summary and Further Reading — 267
- Redis — 248
Part IV. Event and Stream Processing
- 14. Scalable Event-Driven Processing — 271
- Event-Driven Architectures — 272
- Apache Kafka — 274
- Topics — 275
- Producers and Consumers — 276
- Scalability — 279
- Availability — 283
- Summary and Further Reading — 284
- 15. Stream Processing Systems — 287
- Introduction to Stream Processing — 288
- Stream Processing Platforms — 291
- Case Study: Apache Flink — 293
- DataStream API — 293
- Scalability — 295
- Data Safety — 298
- Conclusions and Further Reading — 300
- 16. Final Tips for Success — 303
- Automation — 304
- Observability — 305
- Deployment Platforms — 306
- Data Lakes — 307
- Further Reading and Conclusions — 307
- Index — 309
Preface
Section titled “Preface”Preface
Section titled “Preface”This book is built around the thesis that the ability of software systems to operate at scale is increasingly a key factor that defines success. As our world becomes more interconnected, this characteristic will only become more prevalent. Hence, the goal of this book is to provide the reader with the core knowledge of distributed and concurrent systems. It also introduces a collection of software architecture approaches and distributed technologies that can be used to build scalable systems.
Why Scalability?
Section titled “Why Scalability?”The pace of change in our world is daunting. Innovations appear daily, creating new capabilities for us all to interact, conduct business, entertain ourselves…even end pandemics. The fuel for much of this innovation is software, written by veritable armies of developers in major internet companies, crack small teams in startups, and all shapes and sizes of teams in between.
Delivering software systems that are responsive to user needs is difficult enough, but it becomes an order of magnitude more difficult to do for systems at scale. We all know of systems that fail suddenly when exposed to unexpected high loads—such situations are (in the best cases) bad publicity for organizations, and at worst can result in lost jobs or destroyed companies.
Software is unlike physical systems in that it’s amorphous—its physical form (1s and 0s) bears no resemblance to its actual capabilities. We’d never expect to transform a small village of 500 people into a city of 10 million overnight. But we sometimes expect our software systems to suddenly handle one thousand times the number of requests they were designed for. Unsurprisingly, the outcomes are rarely pretty.