Scalability and Performance
Reason about load, find bottlenecks, and choose scaling strategies proportionate to the requirements.
Introduction
Performance is how fast a system responds under a given load. Scalability is how well it maintains acceptable performance as load grows, and at what cost.
A common failure mode is designing for imaginary scale: a complex distributed system for a product with a hundred users. The opposite failure is a design that cannot grow past its first success. Good architecture sizes the solution to evidence and keeps a clear path for growth.
Learning Objectives
- Estimate load using simple capacity calculations.
- Distinguish latency, throughput, and utilization.
- Identify bottlenecks and choose proportionate scaling strategies.
- Apply caching, asynchronous processing, and data scaling techniques with their costs.
- Plan load tests and performance budgets.
- Use AI for estimation and review while verifying with measurements.
1. Define the Load Model
Start with numbers, even rough ones, labeled as assumptions.
| Quantity | Illustrative SignalDesk assumption (12 months) |
|---|---|
| Workspaces | 500 |
| Items per workspace (typical / largest) | 5,000 / 50,000 |
| Total items | about 2.5 million |
| Active users | 2,000, mostly business hours in a few time zones |
| Concurrent users at peak | about 100 |
| Imports | 300 per day, typical 2,000 rows, largest 10,000 |
| Searches | about 10 per active user per hour |
Derive request rates: 100 concurrent users making a request every 10 seconds gives about 10 requests per second. Peak is usually a multiple of average; add a safety factor and state it.
Such a load is handled by a modest number of application instances and one well-configured database. Seeing this early helps you resist unnecessary complexity.
2. Key Concepts
| Term | Meaning |
|---|---|
| Latency | Time for one request; look at percentiles (p95, p99), not averages |
| Throughput | Requests or jobs completed per unit of time |
| Utilization | How busy a resource is; latency grows sharply near saturation |
| Bottleneck | The resource that limits overall performance |
| Headroom | Spare capacity to absorb spikes |
Averages hide the worst experiences. A p95 target of 1 second says that 5% of requests may take longer; check whether the p99 is also acceptable.
3. Find the Bottleneck First
Optimizing something that is not the bottleneck wastes effort. Typical bottlenecks:
- Database queries lacking indexes or returning too much data.
- N+1 query patterns, where one request triggers many queries.
- Slow synchronous calls to external services.
- CPU-heavy processing in the request path.
- Memory pressure and garbage collection.
- Lock contention.
- Network round trips and large payloads.
Use measurement: profiling, query plans, tracing, and load tests. Guessing is unreliable.
4. Scaling Strategies
| Strategy | Idea | Cost / caveat |
|---|---|---|
| Vertical scaling | Use a larger machine | Simple; finite ceiling; single point of failure |
| Horizontal scaling | Run more instances behind a load balancer | Requires stateless application instances |
| Caching | Keep frequently used results close | Staleness and invalidation complexity |
| Asynchronous processing | Move slow work to queues and workers | Eventual consistency; operational pieces |
| Read replicas | Offload reads from the primary database | Replication lag; routing complexity |
| Partitioning / sharding | Split data across databases | Major complexity; cross-partition queries |
| Content delivery network | Serve static content near users | Cache control for dynamic content |
| Rate limiting / back pressure | Protect the system under overload | Needs clear client behavior |
Apply them in roughly this order: fix inefficiencies, make the application stateless, add caching and asynchronous processing, then replicate, and only last partition. Each step adds cost.
5. Design for Statelessness
For horizontal scaling, application instances should keep no user state in memory. Store sessions or tokens in a shared store or in signed tokens, store files in object storage, and keep jobs in a queue. Then any instance can handle any request, and instances can be added or removed freely. This also supports availability.
6. Caching, Carefully
Caching improves speed and reduces load, but “there are only two hard things: cache invalidation and naming things.”
Before adding a cache, ask:
- What is slow, and what is the measured benefit?
- How stale may the data be?
- What invalidates it?
- Does it risk leaking data between tenants? Include the workspace in every cache key.
- What happens when the cache is empty or unavailable? The system must still work, just slower.
7. Performance Budgets
Break a response target into budgets for each part of the path:
| Search request (target p95 1000 ms) | Budget |
|---|---|
| Network and TLS | 100 ms |
| Authentication and authorization | 50 ms |
| Query execution | 500 ms |
| Serialization and response | 100 ms |
| Margin | 250 ms |
Budgets make design discussions concrete and tell testers what to measure. They are also useful when evaluating whether a new feature fits the target.
8. Test, Don’t Assume
- Create representative data: realistic volumes, distributions, and text.
- Run load tests with realistic scenarios and ramp-up; observe latency percentiles, error rates, and resource use.
- Test the peak and a multiple of it to find the breaking point and the failure mode.
- Run tests regularly, ideally in the delivery pipeline for key scenarios, to catch regressions.
A test on an empty database proves nothing about 2.5 million rows.
9. Use AI for Capacity Reasoning
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Act as a performance engineer.
Load model assumptions (mark as assumptions):
[Paste the load model.]
Design description and performance targets:
[Paste.]
Tasks:
1. Derive request rates and data volumes from the assumptions,
showing the arithmetic.
2. Identify the three most likely bottlenecks and why.
3. Propose the simplest measures that satisfy the targets, in order
of increasing complexity, and the point at which each would become
necessary.
4. Propose a load test plan: scenarios, data volume, metrics, and
pass/fail thresholds.
Do not state benchmark numbers for specific products as facts.
List what should be measured instead.
Check the arithmetic yourself. AI can make calculation errors, or default to complex solutions such as sharding for loads that a single database handles easily.
10. Practical Exercise
- Write a load model with assumptions and derive request rates and storage volumes.
- Produce a performance budget for the search scenario and for CSV import.
- List likely bottlenecks and, for each, the first measure you would try and the metric that shows it is needed.
- Define the scaling path as a sequence of triggers (“when p95 exceeds X for Y days, do Z”).
- Write a load test plan with pass/fail thresholds.
- Run the AI review and verify its arithmetic.
Verification
You are ready to continue when:
- Load assumptions are explicit and derived rates are shown.
- Targets are expressed as percentiles with budgets.
- The scaling approach is proportionate, with triggers for the next step.
- Application instances are designed to be stateless.
- A load-test plan with realistic data exists.
Key Takeaways
- Size the solution to the load model, with headroom, not to imagined scale.
- Measure to find bottlenecks; look at percentiles.
- Scale in order of cost: optimize, stateless instances, cache, asynchronous, replicate, partition.
- AI helps with reasoning and plans; only measurements validate performance.
What’s Next?
Fast systems can still fail. Next, we design for reliability: availability targets, failure modes, resilience patterns, backups, and recovery.