Bird
Raised Fist0
HLDsystem_design~25 mins

Vertical scaling vs horizontal scaling in HLD - Design Approaches Compared

Choose your learning style10 modes available
Design: Scaling a Web Application
Focus on scaling strategies for the application backend and database. Out of scope: frontend design, detailed security implementation.
Functional Requirements
FR1: Support increasing number of users without downtime
FR2: Maintain response time under 200ms for 95% of requests
FR3: Ensure system availability of 99.9% uptime
Non-Functional Requirements
NFR1: Budget limits for hardware and infrastructure
NFR2: Minimal changes to existing application code
NFR3: Support both read and write operations efficiently
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Application servers
Databases
Load balancers
Caching layers
Monitoring tools
Design Patterns
Load balancing
Database replication
Caching
Auto-scaling
Sharding
Reference Architecture
          +-------------------+
          |    Load Balancer   |
          +---------+---------+
                    |
        +-----------+-----------+
        |                       |
+-------+-------+       +-------+-------+
| App Server 1  |       | App Server 2  |
+-------+-------+       +-------+-------+
        |                       |
        +-----------+-----------+
                    |
          +---------+---------+
          |     Database      |
          |  (Vertical Scale) |
          +-------------------+


Alternative Horizontal Scaling:

          +-------------------+
          |    Load Balancer   |
          +---------+---------+
                    |
        +-----------+-----------+
        |           |           |
+-------+-------+ +-------+-------+ +-------+-------+
| App Server 1  | | App Server 2  | | App Server 3  |
+---------------+ +---------------+ +---------------+
                    |
          +---------+---------+
          |   Database Cluster  |
          | (Horizontal Scale)  |
          +--------------------+
Components
Load Balancer
Nginx, HAProxy, or Cloud Load Balancer
Distributes incoming requests evenly across multiple servers
Application Servers
Docker containers or virtual machines
Run the application code; can be scaled vertically or horizontally
Database
PostgreSQL, MySQL, or NoSQL databases
Stores application data; can be scaled vertically by upgrading hardware or horizontally by clustering/sharding
Caching Layer
Redis or Memcached
Speeds up read operations by storing frequently accessed data
Monitoring Tools
Prometheus, Grafana
Track system performance and detect bottlenecks
Request Flow
1. User sends a request to the Load Balancer.
2. Load Balancer forwards the request to one of the Application Servers.
3. Application Server processes the request, querying the Database or Cache as needed.
4. Database responds with data; Cache may serve data faster if available.
5. Application Server sends the response back to the Load Balancer.
6. Load Balancer returns the response to the user.
Database Schema
Entities depend on application domain; scaling strategies apply to the database as a whole rather than schema changes. Vertical scaling upgrades hardware (CPU, RAM) of a single database instance. Horizontal scaling involves database clustering or sharding to distribute data across multiple nodes.
Scaling Discussion
Bottlenecks
Single server CPU or memory limits reached (vertical scaling limit)
Database becomes a single point of failure or performance bottleneck
Load balancer overload if not scaled properly
Network bandwidth saturation
Data consistency challenges in horizontal scaling
Solutions
Vertical scaling: Upgrade server hardware (more CPU, RAM, faster disks) to handle more load on a single machine.
Horizontal scaling: Add more servers behind a load balancer to distribute load; use database replication and sharding to spread data.
Implement caching to reduce database load.
Use auto-scaling groups to add/remove servers based on demand.
Use distributed databases with strong or eventual consistency models depending on requirements.
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying constraints, 20 minutes designing and explaining vertical and horizontal scaling approaches, 10 minutes discussing trade-offs and scaling challenges, 5 minutes for questions.
Explain difference between vertical and horizontal scaling with simple examples (e.g., upgrading a single computer vs adding more computers).
Discuss pros and cons of each approach (cost, complexity, limits).
Mention real-world scenarios where each scaling type is appropriate.
Highlight importance of load balancing and caching in scaling.
Address data consistency and availability trade-offs in horizontal scaling.

Practice

(1/5)
1. Which of the following best describes vertical scaling in system design?
easy
A. Using caching to speed up data access
B. Adding more machines to distribute the workload
C. Splitting data across multiple databases
D. Adding more resources like CPU or RAM to a single machine

Solution

  1. Step 1: Understand vertical scaling definition

    Vertical scaling means improving one machine's capacity by adding resources like CPU, RAM, or storage.
  2. Step 2: Compare with other options

    Options B and C describe horizontal scaling or data partitioning, and D is about caching, not scaling.
  3. Final Answer:

    Adding more resources like CPU or RAM to a single machine -> Option D
  4. Quick Check:

    Vertical scaling = adding resources to one machine [OK]
Hint: Vertical scaling = beef up one machine, not add machines [OK]
Common Mistakes:
  • Confusing vertical scaling with horizontal scaling
  • Thinking adding machines is vertical scaling
  • Mixing caching with scaling
2. Which option correctly shows horizontal scaling in a system architecture?
easy
A. Adding multiple servers behind a load balancer
B. Upgrading the CPU and RAM of a single server
C. Increasing the disk size of one database server
D. Using a faster network switch

Solution

  1. Step 1: Identify horizontal scaling characteristics

    Horizontal scaling means adding more machines to share the workload, often managed by a load balancer.
  2. Step 2: Eliminate other options

    Options B and C describe vertical scaling (upgrading one machine), and D is about network hardware, not scaling.
  3. Final Answer:

    Adding multiple servers behind a load balancer -> Option A
  4. Quick Check:

    Horizontal scaling = add machines behind load balancer [OK]
Hint: Horizontal scaling = add servers, vertical = upgrade one [OK]
Common Mistakes:
  • Choosing upgrading one server as horizontal scaling
  • Confusing network upgrades with scaling
  • Ignoring load balancer role
3. Consider a web application initially running on a single server with 8 CPU cores and 16GB RAM. If the traffic doubles, which scaling approach will likely double the capacity most efficiently?
medium
A. Upgrade the server to 16 CPU cores and 32GB RAM (vertical scaling)
B. Add one more identical server and use a load balancer (horizontal scaling)
C. Add caching layer without changing servers
D. Increase database storage size

Solution

  1. Step 1: Analyze capacity needs for doubled traffic

    Doubling traffic usually requires doubling processing power or distributing load.
  2. Step 2: Compare vertical vs horizontal scaling efficiency

    Vertical scaling (Upgrade the server to 16 CPU cores and 32GB RAM (vertical scaling)) can be costly and limited by hardware max. Horizontal scaling (Add one more identical server and use a load balancer (horizontal scaling)) adds another server to share load, often more efficient and scalable.
  3. Final Answer:

    Add one more identical server and use a load balancer (horizontal scaling) -> Option B
  4. Quick Check:

    Doubling capacity = add server (horizontal) better than upgrade [OK]
Hint: Doubling load? Add servers horizontally, not just upgrade one [OK]
Common Mistakes:
  • Assuming vertical scaling always doubles capacity easily
  • Ignoring load balancer role in horizontal scaling
  • Confusing storage increase with processing capacity
4. A system uses vertical scaling by upgrading a server's CPU and RAM. After some time, the server crashes under load. What is the most likely cause?
medium
A. The server reached hardware limits and cannot scale further vertically
B. The load balancer is misconfigured
C. The database storage is full
D. The network bandwidth is too high

Solution

  1. Step 1: Understand vertical scaling limits

    Vertical scaling improves one machine but has physical hardware limits beyond which it cannot handle more load.
  2. Step 2: Analyze crash cause

    Since the server crashes under load after upgrades, it likely hit max capacity. Other options relate to load balancer, storage, or network, which are less likely causes here.
  3. Final Answer:

    The server reached hardware limits and cannot scale further vertically -> Option A
  4. Quick Check:

    Vertical scaling hits hardware limits causing crashes [OK]
Hint: Vertical scaling hits max hardware limits causing failures [OK]
Common Mistakes:
  • Blaming load balancer when none is used
  • Confusing storage issues with CPU/RAM limits
  • Ignoring hardware capacity limits
5. A startup expects rapid user growth and unpredictable traffic spikes. They want a scalable system with minimal downtime and cost efficiency. Which scaling strategy should they prioritize?
hard
A. Vertical scaling by upgrading a powerful single server
B. Relying on manual server upgrades during peak times
C. Horizontal scaling with multiple servers and auto-scaling
D. Using a single server with a large database

Solution

  1. Step 1: Identify startup needs

    Rapid growth and unpredictable spikes require flexible, scalable solutions that can adjust resources quickly without downtime.
  2. Step 2: Evaluate scaling options for flexibility and cost

    Vertical scaling (Vertical scaling by upgrading a powerful single server) is limited and costly for spikes. Manual upgrades (Relying on manual server upgrades during peak times) cause downtime and delay. Single server (Using a single server with a large database) risks failure. Horizontal scaling with auto-scaling (Horizontal scaling with multiple servers and auto-scaling) adds/removes servers dynamically, balancing cost and uptime.
  3. Final Answer:

    Horizontal scaling with multiple servers and auto-scaling -> Option C
  4. Quick Check:

    Rapid growth needs horizontal auto-scaling for cost and uptime [OK]
Hint: Rapid growth? Use horizontal auto-scaling for flexibility [OK]
Common Mistakes:
  • Choosing vertical scaling for unpredictable spikes
  • Ignoring downtime caused by manual upgrades
  • Relying on single server risking failure
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard