Networking & Web Fundamentals
Scalability
Handling growing load through vertical and horizontal scaling.
In short
Handling growing load through vertical and horizontal scaling.
Scalability is the ability of a system to handle a growing amount of work by adding resources.
- Vertical scaling (scale up) — add more power (CPU, RAM) to a single machine. Simple, but limited by hardware and creates a single point of failure.
- Horizontal scaling (scale out) — add more machines to the pool. Effectively limitless and resilient, but adds complexity (load balancing, data distribution, consistency).
1. Learning Objectives
By the end of this lesson, you will be able to:
- Define scalability and identify key system metrics including throughput, latency, and resource utilization.
- Critically compare vertical scaling (scaling up) and horizontal scaling (scaling out) along the axes of cost, complexity, and reliability.
- Explain the mathematical foundations of scalability, such as Amdahl's Law, and how they apply to distributed workloads.
- Formulate strategies to transition applications from stateful to stateless to enable smooth horizontal web tiers.
- Analyze the critical infrastructure elements required for horizontal scaling: Load Balancers, Consistent Hashing, Replication, and Sharding.
- Diagnose and design mitigations for common scaling failure modes, including replication lag, cascading failures, split-brain scenario, and cache stampedes.
2. Prerequisites
Before diving into scalability, you should have a solid grasp of:
- The Client-Server Model: Understanding HTTP/HTTPS, DNS resolution, and TCP handshake.
- Hardware Fundamentals: Knowing the primary roles of CPU, RAM (Memory), Storage (SSD/NVMe), and Network Interface Cards (NICs).
- Basic Database Concepts: General familiarity with relational databases (SQL, tables, indexes) and non-relational databases (NoSQL).
3. Why This Topic Matters
Scalability is the cornerstone of modern system design. A system that works perfectly for 100 concurrent users will often grind to a halt when hit with 10,000 or 1,000,000 requests. When scalability is not designed into the core architecture from day one:
- Revenue Loss: Application downtime directly correlates to lost sales (e.g., an e-commerce platform crash during Black Friday).
- Brand Damage: Slow response times and persistent error pages erode user trust and push customers toward competitors.
- Financial Inefficiency: Without elasticity (the ability to scale up and down dynamically), a business will waste thousands of dollars over-provisioning servers for off-peak periods.
Mastering scalability means learning how to transform single-node bottlenecks into elastic, resilient, distributed computing topologies that can scale gracefully to meet any volume of global demand.
4. Real-world Analogy
To understand the difference between scaling up and scaling out, imagine running a busy coffee shop:
- Vertical Scaling (Scale Up) is like upgrading your single barista's capabilities. You buy a faster, state-of-the-art espresso machine, put them through intensive barista training, and purchase premium grinders. Now, the single barista can make coffee twice as fast. However, you will eventually hit a hard physical wall: a single human barista has only two hands, can only occupy a limited physical space, and the espresso machine can only brew so quickly. Additionally, if this single barista gets sick or burns out, your entire coffee shop closes immediately (Single Point of Failure).
- Horizontal Scaling (Scale Out) is like opening multiple registers and hiring a team of baristas. Instead of making one barista super-efficient, you set up four identical counters side-by-side with four separate baristas. If one barista is out sick, the other three continue serving customers. While this is incredibly scalable, it introduces logistical challenges: you now need a host at the door to route customers to the shortest line (Load Balancer), and you need a shared inventory manager to ensure all four registers are synchronized on ingredient levels so they don't run out of milk or beans (Data Consistency/Sync).
5. Core Concepts
Let's dissect the fundamental terms and metrics you will encounter in system scalability:
System Load & Traffic Metrics
Load represents the demand placed on a system. It is measured in various dimensions depending on the nature of the application:
- RPS (Requests Per Second): The number of HTTP/HTTPS or RPC requests hitting your application servers.
- Concurrent Connections: The number of active TCP connections currently open (critical for websockets or chat applications).
- Read/Write Ratio: The ratio of read operations to write operations (e.g., 99:1 for social media feeds, 50:50 for collaborative text editors).
Performance Metrics
- Throughput: The number of transactions or processes completed successfully by the system per unit of time (e.g., 10,000 payments processed per second).
- Latency vs. Response Time: Latency is the time a request spends waiting in queues or traveling over the network (e.g., transmission time). Response time is the total duration the user experiences, which includes latency plus server processing time.
- Resource Utilization: The percentage of system resources (CPU, RAM, Disk I/O, Network Bandwidth) currently in use.
Scale Types
- Vertical Scaling (Scale-Up): Upgrading the CPU, RAM, or storage of a single host.
- Horizontal Scaling (Scale-Out): Adding more nodes/machines into your system cluster.
- Elasticity: The ability to dynamically provision and de-provision compute resources automatically in response to real-time traffic fluctuations.
- Stateless Web Tier: Architectural pattern where application servers do not store client session data (e.g., user profiles or shopping cart states) locally. Every request contains all the information needed for processing, allowing any instance to handle any request.
6. Visualization
Here is a conceptual diagram visualizing the differences between the single-node scaling limit (vertical) and multi-node scale-out topologies (horizontal).
Architectural Topologies
7. How It Works
As a startup or application grows, its architecture typically progresses through specific evolutionary stages of scaling:
- Step 1: The All-in-One Server: Both the web application server and the database run on a single physical machine. This configuration is easy to set up but fails quickly as both application logic and database queries compete for the same CPU and memory resources.
- Step 2: Database Separation: Move the database to its own dedicated machine. This separates computing bottlenecks: the app server handles CPU-intensive business logic, while the database server handles memory-intensive indexing and disk I/O.
- Step 3: Vertical Scale-Up: As traffic grows, upgrade both servers to higher-tier hardware specifications (e.g., from 4 cores to 16 cores). This requires zero code changes but hits an eventual performance and physical ceiling.
- Step 4: Decoupling Application State: Before scaling out, session data (such as login states) must be removed from the application server's local RAM. Instead, sessions are stored in client-side JSON Web Tokens (JWTs) or centralized in-memory caches like Redis. This makes the application layer stateless.
- Step 5: Horizontal Scale-Out of the Web Tier: Introduce a Load Balancer (e.g., NGINX, AWS ALB) at the entry point. Deploy multiple stateless application servers behind the load balancer, which distributes traffic among them using algorithms like Round Robin or Least Connections.
- Step 6: Database Replication: Create a database master-replica architecture. The Master database handles all write operations (INSERT, UPDATE, DELETE), while multiple read replicas sync with the master and serve all read queries (SELECT), offloading massive read traffic from the main writer.
- Step 7: Database Sharding: For write-heavy systems, split the database horizontally into multiple logical shards based on a partition key (e.g., user_id). Writes are distributed across different physical database instances, removing the master write bottleneck.
8. Internal Architecture
A horizontally scaled system requires several specialized architectural components working together. The table below outlines these components, their primary roles, scaling vectors, and common failure points:
| Component | Primary Responsibility | Scalability Vector | Common Failure Points |
|---|---|---|---|
| Load Balancer (Layer 4/7) | Routes client traffic; terminates SSL/TLS connections. | DNS Round Robin, clustering load balancers via Anycast. | Single Point of Failure (SPOF) if not redundant; CPU saturation during SSL handshakes. |
| Stateless Web App Tier | Executes business logic, authenticates requests, parses routing. | Horizontal auto-scaling groups based on CPU/Request count. | Memory leaks, thread-pool exhaustion, configuration drift. |
| Distributed Cache Tier | Stores frequently read database query results and sessions in memory. | Partitioning/sharding cache keys across nodes (e.g., Redis Cluster). | Cache stampedes, stale data cache invalidation bugs, memory limit eviction failures. |
| Persistent Database Tier | Provides durable storage, acid guarantees, and transaction handling. | Master-replica replication (reads) and horizontal database sharding (writes). | Replication lag, lock contention, exhaustion of database connection pools. |
| Message Queue / Event Bus | Decouples asynchronous tasks (e.g., video processing, email sending). | Adding partitions/topics (e.g., Kafka partition keys). | Consumer lag (workers too slow), message broker disk filling up, network partitions. |
9. Request Lifecycle
Let's trace how a request flows through a horizontally scaled system:
- DNS Resolution: The client types
https://example.com. The DNS server uses latency-based routing or GeoDNS to resolve the hostname to the IP address of the nearest Load Balancer. - Connection Termination: The request arrives at the Load Balancer (LB). The LB performs SSL/TLS decryption (SSL Termination), freeing downstream app servers from encryption computational overhead.
- Routing Decision: The Load Balancer checks server health metrics and selects an active App Instance (e.g., App Server 3) using the Least Connections algorithm.
- Read operations - Cache Lookup:
- The application server requests the data from a distributed Redis cache.
- Cache Hit: The data is found, skipped database lookup, and returned instantly.
- Cache Miss: The data is not in cache; the server queries a Database Read Replica, stores the result in the cache, and prepares the response.
- Write operations - Master Write:
- The application server sends the transaction write query to the Database Primary/Master node.
- The Primary node applies the change and asynchronously propagates the transaction log to the Read Replicas.
- Response Delivery: The app server returns the HTTP response back to the Load Balancer, which encrypts the payload and delivers it back to the client.
10. Deep Dive
Let's explore key engineering concepts that underwrite scalability in distributed architectures.
Consistent Hashing
In traditional horizontal database or cache scaling, you might assign keys to nodes using a basic modulo algorithm:
This approach breaks catastrophically when you add or remove nodes. If NumberOfNodes changes from 4 to 5, almost every key hashes to a different index. This invalidates the entire cache, sending a massive traffic storm to your database.
Consistent Hashing solves this by mapping both servers (nodes) and keys onto a circular 360-degree ring (the hash space). A key is assigned to the first server it encounters moving clockwise. When a node is added or removed, only a small fraction of keys ($1/N$, where $N$ is the number of nodes) must be remapped, keeping the rest of the cache intact.
Amdahl's Law and Serial Limits
Amdahl's Law explains that the maximum speedup of a program when utilizing multiple processors is limited by the serial (non-parallelizable) portion of the code:
$$S_{latency}(s) = \frac{1}{(1 - p) + \frac{p}{s}}$$
Where $s$ is the speedup factor of the parallelized portion and $p$ is the proportion of execution time that can benefit from parallelization. If 10% of your system logic is inherently sequential (e.g., acquiring a global lock in a database transaction), your maximum system speedup is capped at 10x, even if you add thousands of application servers. Minimizing sequential coordination is key to high scalability.
CAP & PACELC Theorems
The CAP Theorem states that in a distributed database system, you can choose only two of the following: Consistency (all nodes see same data), Availability (every non-failing node returns a response), and Partition Tolerance (the system continues to operate despite network partitions). In practice, since networks are always prone to partitions, database systems must choose between consistency (CP) or availability (AP) when a partition occurs.
PACELC expands this: if there is a Partition, trade off Availability vs Consistency; Else (under normal operations), trade off Latency vs Consistency.
11. Production Example
How Netflix achieves global scalability:
- Autoscaling Web Tier: Netflix uses stateless microservices running on AWS EC2. Because no session state is kept on individual instances, Netflix utilizes AWS Auto Scaling Groups to scale up or down dynamically based on user load and CPU utilization metrics.
- Cassandra for Persistence: For storing user playback profiles, bookmarks, and viewing histories, Netflix uses Apache Cassandra. Cassandra is a wide-column, masterless NoSQL database. It scales linearly horizontally: if you need to double your write throughput capacity, you simply add double the number of database nodes to the ring.
- EVCache Caching Layer: To avoid hammering Cassandra, Netflix relies heavily on EVCache, an in-memory replication system built on top of Memcached. EVCache handles hundreds of millions of operations per second with sub-millisecond latencies, storing frequently accessed metadata (recommendations, movie details).
12. Advantages
Vertical Scaling (Scale-Up)
- Zero Code Changes: The application runs exactly as it did before, only faster. No need to set up load balancers, sharding, or handle distributed consistency.
- Low Latency: Communication between application layers happens on a single machine via memory bus or local IPC rather than over network hops.
- Simpler Maintenance: Only one operating system, one configuration, and one server to log into and monitor.
Horizontal Scaling (Scale-Out)
- Physical Limitlessness: You are not constrained by motherboard layouts. You can scale to thousands of servers.
- High Availability: There is no single point of failure (SPOF). If server 5 crashes, the load balancer reroutes requests to servers 1-4.
- Cost Optimization (Elasticity): You can scale down servers during off-peak times (like nights and weekends) to save on computing costs.
13. Limitations
Vertical Scaling
- Hard Hardware Ceilings: You will eventually reach the limit of how many CPU cores, RAM channels, or network controllers a single server motherboard can house.
- Single Point of Failure: If the motherboard, CPU, or local disk array fails, the entire application goes offline.
- Exponential Cost Curve: Upgrading from a standard server to an ultra-premium, high-core server does not scale linearly in price. Hardware costs rise exponentially at the top end.
- Downtime: Hardware upgrades usually require turning the physical server off, causing service interruption.
Horizontal Scaling
- High Complexity: Requires provisioning extra infrastructure like Load Balancers, API Gateways, service registries, and centralized logging.
- Network Latency: Distributing nodes introduces network hops. Fetching data from other nodes over network switches takes far longer than querying local RAM.
- Eventual Consistency: Master-replica databases suffer from replication lag, meaning reads can briefly serve stale data.
14. Trade-offs
Designing for scalability involves balancing the following crucial architectural trade-offs:
- Throughput vs. Latency: To increase throughput, systems often batch requests (e.g., batching database updates). However, batching increases latency for individual requests because they must wait for the batch to fill.
- Cost vs. Availability: Achieving 99.999% availability requires multi-region active-active horizontal scaling, which replicates database writes across regions. This is highly redundant and significantly more expensive than running a single-region setup.
- Development Speed vs. Operational Scale: Designing for horizontal scaling from day one requires complex architectures (microservices, event-driven message buses). This slows down initial release times compared to deploying a fast, simple monolithic application scaled vertically.
15. Performance Considerations
- Database Connection Pool Saturation: As you scale the web tier from 5 to 50 application nodes, each application server creates its own database connection pool. A single MySQL or PostgreSQL server might quickly exhaust its file descriptors or RAM limits trying to hold open thousands of active connections. Use a connection proxy (like PgBouncer) to pool connections efficiently.
- Serialization Overhead: Horizontal architectures communicate across servers. Moving away from monolithic memory layouts to network APIs (REST, gRPC) introduces CPU bottlenecks due to serialization/deserialization (e.g., turning structures into JSON strings and back).
- Cache Hit Ratio: A scalable system relies on caching to protect the database. If your cache hit ratio drops (e.g., from 95% to 60%), your database will face an unexpected wall of queries, potentially causing database CPU saturation and system failure.
16. Failure Scenarios
Cascading Failures
If one server in a cluster of five crashes due to high traffic, the load balancer redistributes its traffic to the remaining four servers. These servers are now overloaded, causing a second server to fail. This cycle continues until the entire cluster is knocked offline in a cascading domino effect.
Replication Lag & Read-Your-Own-Writes Failure
A user updates their profile picture (write goes to primary database). They refresh the page, and the application routes the read request to a database replica that is currently lagging 3 seconds behind the primary. The page loads with the old profile picture. The user, thinking the upload failed, repeatedly clicks the upload button, worsening write overload.
Split-Brain Scenario
In a clustered database system, a network partition isolates Node A and Node B from Node C and Node D. Node A/B thinks C/D is dead, and elects a new primary. Node C/D also thinks A/B is dead, and elects a separate primary. Clients write conflicting data to both sub-clusters. Once the network partition heals, reconciling the divergent databases causes massive data loss or corruption.
Cache Stampede (Thundering Herd)
A highly popular cache key (e.g., homepage layout data) expires. Suddenly, 50,000 concurrent requests find a cache miss. All 50,000 threads send database queries simultaneously to rebuild the cache key. The database CPU instantly spikes to 100%, causing request timeouts.
17. Best Practices
- Keep Web Tiers Stateless: Store user data in centralized session caches or cryptographically signed tokens (JWTs) so any client request can land on any server.
- Automated Health Checks: Configure load balancers to query a lightweight endpoint (e.g.,
/healthz) on servers. Unhealthy nodes must be automatically removed from the routing pool. - Rate Limiting: Implement rate-limiting proxies at the edge (API Gateway) to protect resources from API abuse, bugs, or denial-of-service (DoS) attacks.
- Use Circuit Breakers: When an external dependency (like a payment processor) is slow or failing, the circuit breaker trips, returning a fallback response immediately instead of letting worker threads pile up and exhaust system memory.
- Asynchronous Processing: Move long-running tasks (e.g., image resizing, generating reports, sending emails) out of the request-response thread lifecycle and place them into worker queues.
18. Common Mistakes
- Scaling the Web Tier, Ignoring the Database: Adding more web servers is easy, but if you don't scale the database through indexing, caching, replica routing, or sharding, the database will become the ultimate system bottleneck.
- Autoscaling with Slow Startup Times: If your application container takes five minutes to boot and start accepting requests (e.g., due to heavy initialization code), autoscaling will fail to absorb sudden traffic spikes in real-time.
- Hardcoding Server IPs: Storing IP addresses directly in client code or application config files. Use DNS names, service discovery (e.g., Consul, Kubernetes DNS), or load balancer entry points instead.
- Ignoring Cross-Zone Transfer Costs: In cloud environments (like AWS), transferring data between different availability zones (AZs) or regions carries financial costs. Scaling horizontal instances randomly across zones without optimizing data locality can lead to massive hidden cloud bills.
19. Implementation
Below is a complete, working TypeScript simulation of a horizontally scaled application cluster. It implements a Load Balancer that dynamically routes requests using the Least-Connections algorithm and simulates performance differences during horizontal scaling (adding nodes) vs. vertical scaling (increasing resources of existing nodes).
20. Interview Questions
Easy Question
Q: What is the difference between horizontal and vertical scaling?
A: Vertical scaling (scaling up) increases the capacity of a single server (more CPU cores, memory/RAM, SSD speed). It is easy to implement and has low operational overhead, but is restricted by a physical hardware ceiling and introduces a single point of failure (SPOF). Horizontal scaling (scaling out) adds more servers of similar specification to a pool. It is practically limitless and highly resilient, but introduces significant design complexity, including the need for load balancers, caching layers, and handling distributed consistency.
Medium Question
Q: How do you scale a stateful system horizontally without losing user session states?
A: There are three main approaches:
- Centralized Session Store: Move session state out of local memory into a shared in-memory database like Redis or Memcached. The application tier remains stateless, and any server can query Redis using the session cookie token. This is the most common industry practice.
- Token-Based Authentication (Stateless JWT): Store the user session data directly in a cryptographically signed token (JSON Web Token) on the client side. The server validates the signature and decodes the payload, requiring no server-side lookup.
- Sticky Sessions (Session Affinity): Configure the load balancer to route all requests from a specific user to the same physical server instance (e.g., using IP hashing or session cookies). However, this makes autoscaling difficult and leads to uneven load distribution if certain sessions are much heavier than others.
Hard Question
Q: What is a Cache Stampede (or Thundering Herd), and how do you design a system to prevent it?
A: A Cache Stampede occurs when a hot cache key expires under heavy traffic. Thousands of concurrent requests find a cache miss and hit the database simultaneously to recompute and write the key, which saturates the database, causes high latencies, and can crash the service.
Mitigation designs include:
- Mutex Locking (Coalescing Requests): When a cache miss occurs, the application node attempts to acquire a distributed lock (e.g., via Redis SETNX) for that key. The first thread to acquire the lock queries the database and updates the cache. Other threads wait or poll the cache, preventing redundant database calls.
- Probabilistic Early Expiration (XFetch algorithm): Instead of waiting for the key to expire, a client requests it, and a probability function determines if the key should be refreshed in the background before its actual expiration, based on how frequently it is requested and how long it takes to compute.
- Background Worker Refresh: Never let user requests trigger cache computation. Run cron jobs or background workers that calculate values and populate the cache periodically.
21. Practice Exercises
Easy Exercise
Design a simple scaling setup for a personal blog website expecting traffic to surge 10x for a single day due to a product announcement. Outline your vertical or horizontal options.
Medium Exercise
Draw a sequence diagram or block diagram showing how you would handle user session failover in a horizontally scaled cluster of 4 nodes when one node suddenly crashes.
Hard Exercise
Develop a pseudocode implementation of consistent hashing with virtual nodes. Show how it behaves when adding a 5th server node to a 4-server cluster containing 10,000 keys.
22. Challenge Problem
Scenario: You are the Lead Architect at a ticketing agency. A globally famous music artist announces a concert tour, and tickets go on sale at exactly 10:00 AM. You expect 1 million concurrent users to hit the system, search for seats, and check out simultaneously.
Design Objectives:
- Prevent the central database from locking and timing out under massive transaction write rates.
- Ensure no ticket is double-booked (strict consistency at checkout).
- Describe how your caching, queueing, load-balancing, and database scaling designs handle the surge.
23. Summary
Scalability is the ability of an infrastructure to process increased loads efficiently. Vertical scaling upgrades existing hardware and is limited by a performance ceiling and high cost. Horizontal scaling aggregates many commodity servers, creating a fault-tolerant and elastic architecture. However, horizontal scaling shifts the burden of software complexity onto engineers, requiring load balancing, stateless app designs, and robust replication/partitioning protocols to manage distributed databases.
24. Cheat Sheet
| Feature | Vertical Scaling (Scale-Up) | Horizontal Scaling (Scale-Out) |
|---|---|---|
| Resources | Add CPU, RAM, Disk to one machine. | Add more machine instances to a cluster. |
| Limits | Bounded by physical hardware limit. | Near-limitless (constrained only by design/budget). |
| Reliability | Single Point of Failure (SPOF). | Highly resilient; nodes failover automatically. |
| Complexity | Low (zero code or config restructuring). | High (requires LBs, replication, shared state management). |
| Cost Model | Exponentially expensive at higher bounds. | Linear cost; commodity hardware; elasticity saves money. |
| Data Storage | Local transactions, acid consistency is simple. | Sharding, eventual consistency, replication lag. |
25. Quiz
-
What is the fundamental limitation of vertical scaling?
A) High network latency between servers.
B) An eventual hardware ceiling and single point of failure.
C) The necessity of rewrite to stateless architecture.
D) Incompatibility with relational databases.
Answer: B
Explanation: Vertical scaling is limited by physical motherboard limits and creates a single point of failure if the single server crashes. -
Which mechanism allows horizontal application scaling without routing users to specific servers based on local session storage?
A) Sticky sessions.
B) Centralized database locks.
C) Decoupling application state into a shared cache or token.
D) Increasing CPU count.
Answer: C
Explanation: By saving sessions in Redis or using signed client tokens (JWTs), the servers become stateless, enabling any node to handle any request. -
What does Amdahl's Law tell us about scaling?
A) Adding servers reduces network latency linearly.
B) Cache hit ratios determine database performance.
C) Maximum system speedup is limited by the serial (non-parallel) components of the system.
D) Databases must choose consistency over availability during network partitions.
Answer: C
Explanation: Amdahl's Law mathematically demonstrates that sequential sections of a codebase limit the speedup gained from parallel nodes. -
In consistent hashing, what percentage of keys must be moved when a new node is added to a cluster of N nodes?
A) 100%
B) Roughly 50%
C) Approximately 1/N
D) 0%
Answer: C
Explanation: Consistent hashing maps keys and nodes to a circular hash ring, requiring only a fraction (1/N) of keys to migrate when servers are added/removed. -
What is "Replication Lag" in master-replica database architectures?
A) The network time it takes for a client to request a transaction.
B) The time delay for writes on the master node to copy over to read replicas.
C) The lag caused by sharding tables horizontally.
D) The startup boot time of a new server container.
Answer: B
Explanation: Replication lag is the time gap between a write being committed on the primary database and it being synchronized to read-only replicas. -
PACELC is an extension of CAP. What does the "E" and "L" stand for?
A) Else, Latency.
B) Eventual, Local.
C) Elasticity, Load.
D) Execution, Log.
Answer: A
Explanation: PACELC stands for: if there is a Partition (P), choose Availability (A) or Consistency (C); Else (E), choose Latency (L) or Consistency (C). -
How does a Circuit Breaker protect a horizontally scaled service?
A) It increases database connection pool limits.
B) It isolates network partitions between databases.
C) It immediately rejects requests to a failing downstream dependency to avoid server thread exhaustion.
D) It encrypts payload packages to reduce serialization size.
Answer: C
Explanation: By failing fast instead of waiting for timeouts on slow dependencies, circuit breakers prevent worker threads from bottlenecking. -
What scenario is described as a "Split-Brain"?
A) A load balancer routing requests randomly.
B) Two segments of a partitioned database cluster acting independently as masters and accepting conflicting writes.
C) An application server mixing read and write database connections.
D) An in-memory cache expiring all of its keys concurrently.
Answer: B
Explanation: Network partitions can isolate server clusters, leading both subgroups to elect a master node, leading to divergent write updates. -
What is the primary trade-off of using request batching to increase database write throughput?
A) Decreased CPU utilization.
B) Increased latency for individual request transactions.
C) Loss of partition tolerance.
D) Increased replication lag.
Answer: B
Explanation: Batching groups multiple transactions together, which increases average throughput but delays individual request processing until the batch executes. -
Why can a low cache hit ratio during a traffic spike crash a database?
A) Because consistent hashing ceases to operate.
B) Because too many cache entries require SSL termination.
C) Because the volume of requests hitting the database exceeds its processing capacity (Cache Stampede).
D) Because connection pooling automatically disables itself.
Answer: C
Explanation: A low cache hit ratio forces web servers to fall back directly to query the database, overloading it and causing queries to time out or crash.
26. Further Reading
- Designing Data-Intensive Applications by Martin Kleppmann - Chapter 1 (Reliability, Scalability, and Maintainability) and Chapter 6 (Partitioning).
- System Design Interview – An insider's guide by Alex Xu - Scale From Zero To Millions of Users.
- Dynamo: Amazon’s Highly Available Key-value Store (ACM Paper on Consistent Hashing).
27. Next Lesson Preview
In the next lesson, we will dive deep into Load Balancers. We will explore the differences between Layer 4 (Transport) and Layer 7 (Application) routing, learn how load balancers monitor node health, and examine load-balancing algorithms like Weighted Round Robin, IP Hash, and Least Connections in production environments.
Key takeaways
- Vertical = simpler but capped; horizontal = scalable but complex.
- Horizontal scaling needs load balancing and data distribution.