Sub topic 1
What scaling means: capacity versus load
Prerequisites
Assume you understand client-server architecture, basic server resources, and the roles of web servers and databases.
Capacity versus load
Capacity is the maximum work a system can handle while meeting its performance target. Load is the work currently requested by users or other systems. Load can include requests per second, concurrent users, stored data, or background jobs.
Scaling means increasing capacity so that load stays within acceptable limits. A system may need more capacity because traffic grows, requests become more expensive, or a failure removes part of the available capacity.
A useful first question is whether the system is overloaded now or whether you are preparing for expected growth. Scaling before measuring can increase cost without fixing the actual problem.
Measuring a system
Measure these three signals together:
| Metric | Meaning | Useful question |
|---|---|---|
| Latency | Time needed to complete one request | Are users waiting too long? |
| Throughput | Work completed per unit of time | How many requests or jobs can finish? |
| Utilization | Fraction of a resource currently in use | Which resource is close to its limit? |
Latency is often reported with percentiles. For example, p95 latency is the time below which 95% of requests finish. Averages can hide slow requests.
Throughput may rise with load until a resource reaches its limit. After that point, queues grow and latency usually increases. CPU, memory, disk I/O, network bandwidth, database connections, and locks can all become limiting resources.
Finding the bottleneck before you scale
A bottleneck is the component that limits the system's overall capacity. Correlate latency and throughput with resource measurements. High CPU utilization with saturated CPU and increased latency suggests a CPU bottleneck. Normal CPU with slow database queries suggests scaling the application server will not solve the problem.
Trace a slow request through each dependency. Check whether the delay comes from application code, storage, a database, a network call, or contention. Fixing a bottleneck can provide more capacity than adding machines.
Vertical scaling: a bigger machine
Vertical scaling, or scaling up, increases the resources of one machine: more CPU, memory, faster disks, or greater network capacity. It is simple because the application often needs no architectural change.
Its limits are the largest available machine, upgrade downtime, and the risk of concentrating work on one host. A larger machine also costs more, and a failure can remove the entire service.
Exercise
A web server has 20% CPU use, slow database queries, and rising request latency. What should you investigate first?
Show answer
Investigate the database queries and database resources. Scaling the web server vertically would not address the measured bottleneck.