In many systems, scalability becomes the primary driver as the user base grows. Attractive features and high utility breed success, which brings more requests to handle and more data to manage. But organizations reach a tipping point when design decisions that made sense under light loads suddenly become technical debt. This practical book covers design approaches and technologies that make it possible to scale an application quickly and cost-effectively. Author Ian Gorton takes software architects and developers through the foundational principles of distributed systems. You'll explore the essential ingredients of scalable solutions, including replication, state management, load balancing, and caching. Specific chapters focus on the implications of scalability for databases, microservices, and event-based streaming systems. You will focus on: • Foundations of scalable systems: Learn basic design principles of scalability, its costs, and architectural tradeoffs • Designing scalable services: Dive into service design, caching, asynchronous messaging, serverless processing, and microservices • Designing scalable data systems: Learn data system fundamentals, NoSQL databases, and eventual consistency versus strong consistency • Designing scalable streaming systems: Explore stream processing systems and scalable event-driven processing Cover 1 Copyright 6 Table of Contents 7 Preface 13 Why Scalability? 13 Who This Book Is For 14 What You Will Learn 14 Note for Educators 15 Conventions Used in This Book 15 Using Code Examples 16 O’Reilly Online Learning 16 How to Contact Us 17 Acknowledgments 17 Part I. The Basics 19 Chapter 1. Introduction to Scalable Systems 21 What Is Scalability? 21 Examples of System Scale in the Early 2000s 24 How Did We Get Here? A Brief History of System Growth 25 Scalability Basic Design Principles 27 Scalability and Costs 29 Scalability and Architecture Trade-Offs 31 Performance 31 Availability 32 Security 33 Manageability 34 Summary and Further Reading 34 Chapter 2. Distributed Systems Architectures: An Introduction 37 Basic System Architecture 37 Scale Out 39 Scaling the Database with Caching 41 Distributing the Database 43 Multiple Processing Tiers 45 Increasing Responsiveness 48 Systems and Hardware Scalability 50 Summary and Further Reading 52 Chapter 3. Distributed Systems Essentials 53 Communications Basics 53 Communications Hardware 54 Communications Software 57 Remote Method Invocation 61 Partial Failures 67 Consensus in Distributed Systems 71 Time in Distributed Systems 74 Summary and Further Reading 76 Chapter 4. An Overview of Concurrent Systems 79 Why Concurrency? 80 Threads 82 Order of Thread Execution 85 Problems with Threads 86 Race Conditions 87 Deadlocks 91 Thread States 96 Thread Coordination 97 Thread Pools 100 Barrier Synchronization 102 Thread-Safe Collections 104 Summary and Further Reading 106 Part II. Scalable Systems 109 Chapter 5. Application Services 111 Service Design 111 Application Programming Interface (API) 112 Designing Services 115 State Management 118 Applications Servers 121 Horizontal Scaling 124 Load Balancing 125 Load Distribution Policies 127 Health Monitoring 127 Elasticity 128 Session Affinity 129 Summary and Further Reading 131 Chapter 6. Distributed Caching 133 Application Caching 133 Web Caching 138 Cache-Control 139 Expires and Last-Modified 139 Etag 140 Summary and Further Reading 142 Chapter 7. Asynchronous Messaging 145 Introduction to Messaging 146 Messaging Primitives 146 Message Persistence 148 Publish–Subscribe 149 Message Replication 150 Example: RabbitMQ 151 Messages, Exchanges, and Queues 151 Distribution and Concurrency 153 Data Safety and Performance Trade-offs 156 Availability and Performance Trade-Offs 158 Messaging Patterns 159 Competing Consumers 159 Exactly-Once Processing 160 Poison Messages 161 Summary and Further Reading 162 Chapter 8. Serverless Processing Systems 165 The Attractions of Serverless 165 Google App Engine 167 The Basics 167 GAE Standard Environment 167 Autoscaling 168 AWS Lambda 170 Lambda Function Life Cycle 171 Execution Considerations 172 Scalability 173 Case Study: Balancing Throughput and Costs 175 Choosing Parameter Values 176 GAE Autoscaling Parameter Study Design 177 Results 178 Summary and Further Reading 179 Chapter 9. Microservices 181 The Movement to Microservices 182 Monolithic Applications 182 Breaking Up the Monolith 184 Deploying Microservices 186 Principles of Microservices 188 Resilience in Microservices 190 Cascading Failures 191 Bulkhead Pattern 196 Summary and Further Reading 198 Part III. Scalable Distributed Databases 201 Chapter 10. Scalable Database Fundamentals 203 Distributed Databases 203 Scaling Relational Databases 204 Scaling Up 204 Scaling Out: Read Replicas 206 Scale Out: Partitioning Data 207 Example: Oracle RAC 209 The Movement to NoSQL 210 NoSQL Data Models 214 Query Languages 215 Data Distribution 216 The CAP Theorem 220 Summary and Further Reading 221 Chapter 11. Eventual Consistency 223 What Is Eventual Consistency? 223 Inconsistency Window 224 Read Your Own Writes 225 Tunable Consistency 227 Quorum Reads and Writes 229 Replica Repair 231 Active Repair 232 Passive Repair 232 Handling Conflicts 233 Last Writer Wins 234 Version Vectors 235 Summary and Further Reading 239 Chapter 12. Strong Consistency 241 Introduction to Strong Consistency 242 Consistency Models 244 Distributed Transactions 245 Two-Phase Commit 246 2PC Failure Modes 248 Distributed Consensus Algorithms 250 Raft 252 Leader Election 254 Strong Consistency in Practice 256 VoltDB 256 Google Cloud Spanner 259 Summary and Further Reading 262 Chapter 13. Distributed Database Implementations 265 Redis 266 Data Model and API 266 Distribution and Replication 268 Strengths and Weaknesses 269 MongoDB 271 Data Model and API 272 Distribution and Replication 274 Strengths and Weaknesses 277 Amazon DynamoDB 278 Data Model and API 279 Distribution and Replication 282 Strengths and Weaknesses 284 Summary and Further Reading 285 Part IV. Event and Stream Processing 287 Chapter 14. Scalable Event-Driven Processing 289 Event-Driven Architectures 290 Apache Kafka 292 Topics 293 Producers and Consumers 294 Scalability 297 Availability 301 Summary and Further Reading 302 Chapter 15. Stream Processing Systems 305 Introduction to Stream Processing 306 Stream Processing Platforms 309 Case Study: Apache Flink 311 DataStream API 311 Scalability 313 Data Safety 316 Conclusions and Further Reading 318 Chapter 16. Final Tips for Success 321 Automation 322 Observability 323 Deployment Platforms 324 Data Lakes 325 Further Reading and Conclusions 325 Index 327 About the Author 339 Colophon 339 In many systems, scalability becomes the primary driver as the user base grows. Attractive features and high utility breed success, which brings more requests to handle and more data to manage. But organizations reach a tipping point when design decisions that made sense under light loads suddenly become technical debt. This practical book covers design approaches and technologies that make it possible to scale an application quickly and cost-effectively.Author Ian Gorton takes software architects and developers through the principles of foundational distributed systems. You'll explore the essential ingredients of scalable solutions, including replication, state management, load balancing, and caching. Specific chapters focus on the implications of scalability for databases, microservices, and event-based streaming systems.You will focus on:• Foundations of scalable systems: Learn basic design principles of scalability, its costs, and architectural tradeoffs• Designing scalable services: Dive into service design, caching, asynchronous messaging, serverless processing, and microservices• Designing scalable data systems: Learn data system fundamentals, NoSQL databases, and eventual consistency versus strong consistency• Designing scalable streaming systems: Explore stream processing systems and scalable event-driven processing