Scalability
As an application grows, the number of users, requests, and amount of data also increases. A system that works perfectly for 1,000 users may struggle when it reaches 1 million users.
This is where scalability becomes important. A scalable system can handle increasing demand by adding resources without requiring a complete redesign.
1. What is Scalability?
Scalability is the ability of a system to handle increased load by adding resources.
The goal isn’t simply to make a system faster. The goal is to make sure the system can continue performing reliably as the number of users, requests, and data grows.
For example, an application handling 1,000 requests per second today might need to handle 100,000 requests per second in the future.
Process
- Users send requests to the application.
- The system measures the current workload.
- Traffic starts increasing.
- The system identifies the bottleneck.
- Additional resources are added.
- Traffic is distributed efficiently.
- The system continues serving users without major performance degradation.
Example
Imagine JK, Jyotirmoy, and Bishal launch a university notes application.
Initially, only 100 students use it, so one server is enough.
But when 50,000 students start using it simultaneously, the server becomes overloaded.
Instead of letting the application crash, they scale the system by adding more resources and distributing the workload.
2. Measuring Scalability
Before scaling a system, we need to understand how much load it is currently handling.
Important metrics include:
- Requests Per Second (RPS) → Number of requests handled per second.
- Concurrent Users → Users active at the same time.
- Data Volume → Amount of stored or processed data.
- Throughput → Amount of data processed per unit of time.
- Query Rate → Database queries per second.
- Message Rate → Messages processed through a queue per second.
Process
- Measure the current traffic.
- Measure response time.
- Monitor CPU and memory usage.
- Monitor database queries.
- Identify the bottleneck.
- Increase the load gradually.
- Observe how the system behaves.
Example
Suppose:
JK sends 100 requests/sec.
Jyotirmoy sends 200 requests/sec.
Bishal sends 300 requests/sec.
The system now needs to handle 600 requests/sec.
If response time suddenly increases from 50 ms to 500 ms, we know that the system is approaching a scalability bottleneck.
3. Vertical Scaling
Vertical Scaling, also called Scaling Up, means making an existing server more powerful instead of adding more servers.
We can increase:
- CPU
- RAM
- Storage
- Network capacity
For example, we can upgrade a server from 4 CPU cores and 16 GB RAM to 16 CPU cores and 64 GB RAM.
Process
- Start with one server.
- Traffic increases.
- Monitor resource usage.
- Identify insufficient CPU/RAM/storage.
- Upgrade the server.
- The server can now handle more traffic.
- Continue until the hardware limit is reached.
Example
Suppose JK, Jyotirmoy, and Bishal’s notes application initially runs on:
4 CPU + 8 GB RAM
As more students join, they upgrade it to:
16 CPU + 32 GB RAM
The same server can now handle more requests.
However, eventually the server reaches its maximum capacity.
Advantages
- Simple
- No major architectural changes
- Lower network complexity
- Easy to implement
Disadvantages
- Hardware has limits
- Expensive at higher capacities
- Single point of failure
- Upgrades may require downtime
4. Horizontal Scaling
Horizontal Scaling, also called Scaling Out, means adding more servers instead of making one server more powerful.
For example:
Load Balancer
/ | \
Server 1 Server 2 Server 3Instead of one powerful server handling everything, multiple servers share the workload.
Process
- Start with one application server.
- Traffic increases.
- One server approaches its capacity.
- Add additional servers.
- Place a load balancer in front.
- Distribute requests across servers.
- Add more servers whenever traffic increases.
Example
JK, Jyotirmoy, and Bishal’s university app becomes popular.
Instead of upgrading one massive server, they deploy:
- Server 1
- Server 2
- Server 3
- Server 4
The load balancer distributes students among them.
If Server 2 crashes, the remaining servers continue handling requests.
Advantages
- Better fault tolerance
- Can keep adding servers
- Better handling of traffic spikes
- Geographic distribution is possible
Disadvantages
- More architectural complexity
- Data synchronization becomes harder
- Network communication introduces overhead
- Applications usually need to be stateless
5. Stateless vs Stateful Services
For horizontal scaling to work effectively, application servers should ideally be stateless.
A stateless server does not keep a user’s session data locally. Therefore, any server can handle the next request.
Session information can instead be stored in a shared system such as Redis.
Process
- User sends a request.
- Load balancer selects any server.
- Server retrieves session information from Redis.
- Server processes the request.
- Response is returned.
- The next request can go to another server.
Example
Suppose:
- JK’s first request → Server 1
- JK’s second request → Server 3
- JK’s third request → Server 2
Because his session is stored in Redis, all three servers can understand who JK is.
6. Database Scaling
Databases are usually harder to scale than application servers because they manage state, consistency, durability and transactions.
Get Rajdeep Mudiar’s stories in your inbox
Join Medium for free to get updates from this writer.
Different database bottlenecks require different solutions:
- Read-heavy → Read Replicas
- Write-heavy → Sharding
- Read + write heavy → Sharding + Replicas
- Flexible large-scale workloads → NoSQL
Process
- Monitor database performance.
- Identify whether reads or writes are the bottleneck.
- If reads dominate → add replicas.
- If data/write volume becomes huge → shard the database.
- Consider NoSQL for suitable workloads.
- Continuously monitor performance.
Example
JK, Jyotirmoy, and Bishal notice that students mostly read notes rather than upload them.
Instead of increasing the primary database’s power, they add multiple read replicas.
Now read requests can be distributed.
7. Read Replication
In a read-heavy system, we can create copies of the primary database called read replicas.
The primary handles writes while replicas handle reads.
Process
- Application sends a write request.
- Primary database processes it.
- Changes are replicated.
- Users send read requests.
- Read requests are distributed among replicas.
- Primary handles critical writes.
Example
JK uploads a new note.
JK → Primary Database
↓
Replication
↙ ↘
Replica 1 Replica 2Jyotirmoy and Bishal can retrieve notes from the replicas without overloading the primary database.
8. Database Sharding
When a database becomes extremely large, we can split the data across multiple databases.
This technique is called Sharding.
For example:
Users A-H → Shard 1
Users I-P → Shard 2
Users Q-Z → Shard 3Each shard stores only a portion of the total data.
Process
- Choose a sharding key.
- Divide data according to that key.
- Route requests to the correct shard.
- Each shard handles its own data.
- Add more shards as data grows.
Example
Suppose the university application has millions of students.
The team decides to shard by student ID:
- IDs 1–1,000,000 → Shard 1
- IDs 1,000,001–2,000,000 → Shard 2
- IDs 2,000,001+ → Shard 3
Now the workload is distributed.
9. Caching
Caching stores frequently accessed data in memory so applications don’t repeatedly retrieve it from the database.
A common approach is the Cache-Aside Pattern.
Process
- User requests data.
- Application checks the cache.
- Cache hit → return data immediately.
- Cache miss → query the database.
- Store the result in cache.
- Return the data.
- Future requests use the cached copy.
Example
JK opens the same popular mathematics note repeatedly.
The first request:
Application → Redis ❌
↓
Database
↓
Redis ✅The next request:
Application → Redis ✅ → UserThe database doesn’t need to process the same request repeatedly.
10. Message Queues
A message queue allows services to communicate asynchronously.
Instead of one service waiting for another service to finish, it places a message in a queue and continues working.
The consumer processes the message when it is ready.
Process
- Producer creates a message.
- Message enters the queue.
- Queue temporarily stores it.
- Consumer retrieves the message.
- Consumer processes it.
- More consumers can be added when traffic increases.
Example
Suppose JK uploads a large video.
Instead of making him wait while the video is processed:
JK
↓
Upload Service
↓
Message Queue
↓
Video Processing ServiceThe upload service can immediately respond while the processing service handles the video in the background.
11. Scaling a Real Application
Scalability usually happens step by step.
We don’t immediately build a massive distributed architecture. We identify the current bottleneck and introduce the simplest solution that solves it.
The source demonstrates a social media application growing from 0 to millions of users through multiple stages.
Process
Stage 1 — Single Server
Users → Application + MySQLGood for small applications.
Stage 2 — Separate Database
Users → App Server → MySQLApplication and database can now scale independently.
Stage 3 — Add Cache
Users → App → Redis → MySQLFrequently accessed data is served from memory.
Stage 4 — Multiple App Servers
Users
↓
Load Balancer
↙ ↓ ↘
App App App
↓
Redis
↓
MySQLApplication traffic is distributed.
Stage 5 — Read Replicas
┌→ Replica 1
App → Primary ┤
└→ Replica 2Reads are distributed across replicas.
Stage 6 — Sharding
Shard Router
/ | \
Shard 1 Shard 2 Shard 3Data and workload are distributed across multiple databases.
Example
Imagine JK, Jyotirmoy, and Bishal build a social media platform for their university.
At first: 100 users → Single Server
Then the application grows: 10,000 users → Separate Database
Then: 100,000 users → Redis Cache
Then: 1 million users → Multiple App Servers + Load Balancer
Then: 10 million users → Read Replicas
Finally: Millions of users + huge data → Sharding
The important lesson is that they don’t scale everything at once.
They identify the bottleneck and solve that bottleneck.
Final Takeaway
Scalability isn’t about blindly adding more servers.
It’s about understanding where the bottleneck is and choosing the right solution.
- Vertical Scaling → Make one machine more powerful.
- Horizontal Scaling → Add more machines.
- Stateless Services → Allow requests to reach any server.
- Read Replicas → Scale database reads.
- Sharding → Distribute huge datasets and workloads.
- Caching → Serve frequently accessed data from memory.
- Message Queues → Process asynchronous workloads independently.
- Load Balancing → Distribute traffic across servers.
The most important principle is:
Always identify the bottleneck first before deciding how to scale.
Adding more application servers won’t help if the real problem is your database.





