Performance vs Scalability¶
Definitions¶
-
Scalable — a service is scalable if adding resources results in a proportional increase in performance. "Performance" usually means serving more units of work, but it can also mean handling larger units of work (for example, as datasets grow).
-
Performance — how fast a system is for a single unit of work.
A simple way to tell them apart¶
| Problem | Symptom |
|---|---|
| Performance problem | The system is slow for a single user. |
| Scalability problem | The system is fast for a single user, but slow under heavy load. |
Key takeaways¶
-
Adding resources (servers, memory, cores) should yield roughly linear gains — that's the definition of scalability.
-
You can have a perfectly performant system that falls over when load increases (poor scalability), and vice versa.
-
Scalability is about the relationship between added resources and added throughput, not about raw speed.
Common Interview Questions¶
Design a system that scales to millions of users on AWS
Why it's asked here: the classic "scale from 1 user to 1M+ users" question tests whether you understand the difference between making a system fast (performance) and making it scale.
Key points to discuss:
-
Start single-server, then grow: separate DB, add read replicas, add a cache, add a load balancer, scale the web tier horizontally (stateless clones).
-
Vertical scaling (a bigger box) hits a ceiling; horizontal scaling (more boxes) is the scalable path.
-
Emphasize the proportional relationship: doubling servers should roughly double capacity.
-
Show that each step removes a specific bottleneck (CPU, DB reads, sessions, etc.).
flowchart LR
U[Users] --> DNS[DNS]
DNS --> LB[Load Balancer]
LB --> W1[Web 1]
LB --> W2[Web 2]
LB --> WN[Web N]
W1 & W2 & WN --> C[(Redis cache)]
W1 & W2 & WN --> M[(DB master)]
M --> R[(Read replicas)]
Design a system that serves data from multiple data centers
Why it's asked here: multi-DC design is fundamentally a scalability/performance story — you trade consistency for the ability to serve more users in more places.
Key points to discuss:
- Route users to the nearest DC (geo/latency-based DNS) to cut latency.
- Replicate data across DCs (eventual consistency) vs paying for strong consistency.
- How added DCs increase throughput but introduce replication lag and conflicts.
- Tie back to "performance = fast for one user; scalability = fast under load".
flowchart LR
U[Users] --> DNS[Geo DNS]
DNS --> DC1[DC US]
DNS --> DC2[DC EU]
DNS --> DC3[DC Asia]
DC1 <-->|async replication| DC2
DC2 <-->|async replication| DC3
Further reading¶
Scaling to Millions of Users on AWS¶
To plan a system for millions of users on AWS, first define the workload. The service must support low-latency reads and writes, high availability, and horizontal growth as traffic increases by orders of magnitude. For a typical consumer application, assume 10 million registered users, 1 million daily active users, and a peak of 10,000 requests per second. User-facing requests are mostly reads, perhaps 10:1 read-to-write, so the architecture optimizes for read throughput without sacrificing write durability.
The high-level architecture uses Route 53 for DNS, CloudFront for static and edge-cached content, an Application Load Balancer for path-based routing, and stateless EC2 or ECS application servers in an Auto Scaling group. The web tier is separated from the application tier so each scales independently. Requests flow from the browser to Route 53, then to CloudFront; uncached dynamic requests go to the Application Load Balancer, which spreads them across multiple stateless app nodes. App nodes coordinate through ElastiCache Redis and read and write data in Amazon RDS or DynamoDB.
The data model is split by access pattern. User accounts, orders, and other relational data live in RDS using normalized SQL tables, because these require transactions, uniqueness, and indexed lookups. Session state, hot user profiles, and query results live in Redis because they are high-volume and can be recreated or refreshed from the source of truth. For very large write streams or sparse records, DynamoDB is used for horizontal partitioning by partition key. Read-heavy SQL tables grow through read replicas, while write-heavy tables are sharded by user or tenant ID.
The core mechanism is removing each bottleneck as the user base grows. The system starts as a single EC2 instance with a local database, then the database is moved to RDS, reads are offloaded to read replicas, a Redis cache absorbs hot reads, and the app tier becomes stateless behind an Application Load Balancer so adding servers increases capacity nearly linearly. As load increases further, the SQL database is sharded, DNS routes users to the nearest region, and asynchronous workers handle email, push, image processing, and analytics so synchronous requests stay fast.
Scaling and availability come from redundancy, statelessness, and managed AWS primitives. The app tier uses Auto Scaling across Availability Zones so a failed instance or Availability Zone does not take down the system. RDS Multi-AZ provides automated failover for writes, while read replicas serve high read throughput. Redis is used for caching and short-lived state, with failover to a replica. CloudFront reduces both origin load and latency by serving cached static assets from edge locations. S3 stores files and static assets with high durability. For multi-region availability, Route 53 failover routing sends traffic away from an unhealthy region, but cross-region data replication must be designed carefully because it adds cost and consistency lag.
The main trade-offs are cost versus availability and consistency versus latency. Read replicas and Redis improve read performance but introduce replication lag and stale-cache risks. Sharding increases write throughput but makes cross-shard joins and operations harder. Stateless servers and external sessions make scaling easier but require extra infrastructure, such as Redis or RDS, that must itself be highly available. Finally, using multiple Availability Zones and CloudFront minimizes downtime and latency but increases complexity and AWS spend.
flowchart LR
U[Users] --> R53[Route 53]
R53 --> CF[CloudFront]
CF --> ALB[Application Load Balancer]
ALB --> W1[EC2/ECS App 1]
ALB --> W2[EC2/ECS App 2]
W1 & W2 --> C[(ElastiCache Redis)]
W1 & W2 --> P[(RDS Primary)]
P --> R[(RDS Read Replicas)]
W1 & W2 --> D[(DynamoDB)]
W1 & W2 --> S3[(S3)]
W1 & W2 --> Q[SQS]
Q --> Worker[Async Workers]
Design a System That Serves Data from Multiple Data Centers¶
Assume the system serves 100 million globally distributed users, with about 20,000 reads per second and 2,000 writes per second at peak. The working dataset is about 50 TB of user data and metadata, replicated across three data centers. The main functional requirement is to allow users to read and write the same logical data from any data center. The non-functional requirements are low latency for nearby users, high availability during a data center failure, and the ability to keep serving traffic even when cross-data-center links are slow or partitioned.
The high-level architecture places a geo-aware DNS service in front of several independent data centers. Each data center contains the same types of components: a load balancer, stateless application services, a local cache tier, a local database, and object storage for large files. When a user makes a request, geo DNS resolves the service name to the IP address of the nearest healthy data center, usually using latency-based routing and health checks. The request then enters that data center through its load balancer, which forwards it to a stateless service. Reads are served from the local cache when possible and otherwise from the local database. Writes are committed locally and then replicated to the other data centers, either synchronously for strongly consistent data or asynchronously for data that can tolerate staleness.
The key data model separates structured transactional data from high-volume or large-object data. User accounts, billing records, and content metadata can live in a relational database because they need strict indexes and transactional correctness. Session data, feed data, or activity counters can live in a NoSQL store because they are high-volume and can tolerate eventual consistency. Large binary content, such as images or files, belongs in object storage because object storage is cheap, durable, and replicated independently. User data is sharded by user ID within each data center. The same logical shard exists in every data center, and cross-data-center replication moves writes from the accepting shard to the matching shards elsewhere.
The core mechanism is the combination of geo-routing and cross-data-center replication. Geo-routing solves proximity by sending users to the nearest data center, which reduces network round-trip time. Replication solves data locality by making a copy of the data available in every data center. A write arriving in one data center is accepted by the local database, assigned a monotonic version or timestamp, and published to a replication stream. Other data centers apply the write asynchronously and update their local replicas. Reads normally use the local copy and do not coordinate with remote data centers, which keeps read latency low and improves availability during network partitions. Conflict handling is required when the same record is edited in two data centers before replication finishes. Options include last-write-wins using timestamps, version vectors that detect conflicts, or CRDTs for data structures that can merge automatically. For data that cannot tolerate conflicts, the system can use a single-region owner for that record or require a synchronous quorum before returning success.
For scaling and availability, every application tier is stateless and runs behind a load balancer, so each data center can scale horizontally by adding more servers. Local caches reduce database load and smooth read-heavy traffic. Databases are sharded within each data center and replicated locally to survive machine failures. Geo DNS performs continuous health checks and removes an unhealthy data center from rotation, allowing traffic to shift to the next nearest region. Cross-data-center replication uses a durable queue or log so a failed data center can catch up after it recovers without losing accepted writes. If a data center becomes unreachable, the remaining centers continue serving read and write traffic under the consistency policy chosen for each dataset. This design therefore improves availability and throughput as data centers are added, at the cost of replication lag, possible stale reads, and more complex conflict resolution.
The main trade-off is latency and availability versus consistency. Asynchronous replication lets users read and write locally with low latency and allows the system to keep operating during a partition, but it means remote replicas may return stale data and writes can conflict. Synchronous replication provides stronger consistency because a write is not acknowledged until it reaches enough data centers, but it increases write latency and can make the system unavailable when a remote data center or network path fails. Another trade-off is operational cost versus redundancy: replicating all data to multiple data centers increases storage and bandwidth costs, so some systems replicate only metadata and hot data everywhere while keeping cold data in a subset of regions. Geo-routing also depends on DNS caching, so failover is not instant because clients and resolvers may cache old IP addresses for a few seconds or minutes.
flowchart LR
U[User] --> D[Geo DNS]
D --> DC1[Data Center West]
D --> DC2[Data Center East]
D --> DC3[Data Center Europe]
subgraph DC1[Data Center West]
LB1[Load Balancer] --> S1[Stateless Services]
S1 --> C1[(Local Cache)]
S1 --> DB1[(Local Sharded DB)]
S1 --> OS1[(Object Storage)]
end
subgraph DC2[Data Center East]
LB2[Load Balancer] --> S2[Stateless Services]
S2 --> C2[(Local Cache)]
S2 --> DB2[(Local Sharded DB)]
S2 --> OS2[(Object Storage)]
end
subgraph DC3[Data Center Europe]
LB3[Load Balancer] --> S3[Stateless Services]
S3 --> C3[(Local Cache)]
S3 --> DB3[(Local Sharded DB)]
S3 --> OS3[(Object Storage)]
end
DC1 <-->|async replication| DC2
DC2 <-->|async replication| DC3
DC1 <-->|async replication| DC3