Database Scaling: Vertical and Horizontal

Watch the video to deepen your understanding.
SubscribeComplete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Database Scaling: Vertical and Horizontal
As your application grows, the volume of data and the number of concurrent users will inevitably increase. If your database cannot handle this load, your application will suffer from latency, timeouts, and potential downtime. Database scaling is the process of adjusting your database infrastructure to meet these changing demands.
This lesson explores the two primary strategies for scaling relational databases: Vertical Scaling and Horizontal Scaling.
1. Vertical Scaling (Scaling Up)
Vertical scaling, often called "scaling up," involves increasing the capacity of a single existing server. You achieve this by adding more power to the machine—typically by upgrading the CPU, increasing RAM, or adding faster SSD storage.
How it Works
Think of vertical scaling as upgrading a computer. If your database is running on a server with 8GB of RAM and you start hitting memory limits, you swap that server for one with 64GB of RAM.
Practical Example
Imagine an e-commerce platform running on a single PostgreSQL instance. During a flash sale, the CPU usage hits 100% because of complex JOIN queries.
- The Action: You migrate the database from a
db.m5.largeinstance (2 vCPUs, 8GB RAM) to adb.m5.4xlargeinstance (16 vCPUs, 64GB RAM). - The Result: The queries execute faster, and the system handles the spike without needing to change your application code.
💡 Key Insight
Vertical scaling is generally the "path of least resistance." It requires no changes to your application logic, database schema, or connection strings.
2. Horizontal Scaling (Scaling Out)
Horizontal scaling, or "scaling out," involves adding more servers to your database architecture. Instead of making one server bigger, you distribute the data and the workload across a cluster of multiple smaller servers.
How it Works
In relational databases (RDBMS), horizontal scaling is typically achieved through Read Replicas or Sharding.
A. Read Replicas
You maintain one "Primary" node for write operations (INSERT, UPDATE, DELETE) and multiple "Replica" nodes for read operations (SELECT).
Code Example (Application Logic): Many modern ORMs allow you to configure separate connection strings for read and write operations:
# Pseudo-code for a database connection manager
DATABASE_CONFIG = {
"write_node": "primary-db-cluster.aws.com",
"read_nodes": [
"replica-1.aws.com",
"replica-2.aws.com"
]
}
def get_db_connection(query_type):
if query_type == "READ":
# Load balance between replicas
return connect(random.choice(DATABASE_CONFIG["read_nodes"]))
else:
return connect(DATABASE_CONFIG["write_node"])
B. Sharding
Sharding involves partitioning your data across multiple database instances. For example, users with IDs 1–1,000,000 might live on DB_Shard_A, while users 1,000,001–2,000,000 live on DB_Shard_B.
Comparison Table
| Feature | Vertical Scaling | Horizontal Scaling |
|---|---|---|
| Complexity | Low | High |
| Cost | High (Hardware costs rise exponentially) | Variable (Uses commodity hardware) |
| Availability | Single point of failure | High (Distributed nodes) |
| Limits | Hard limit (Maximum server size) | Virtually unlimited |
Best Practices
- Start Vertical, Scale Horizontal: Always start by scaling vertically. It is cheaper in terms of engineering time. Only move to horizontal scaling when you hit the physical limits of a single machine or when your budget for high-end hardware becomes unsustainable.
- Optimize Queries First: Before spending money on hardware, ensure your database is optimized. Check for missing indexes, N+1 query problems, and inefficient table scans. Hardware cannot fix bad code.
- Implement Read/Write Splitting: If your application is read-heavy (like a news site or a blog), implementing read replicas provides the best return on investment for scaling.
- Monitor Everything: Use tools like Prometheus, Grafana, or cloud-native monitoring (e.g., AWS CloudWatch) to track CPU, RAM, IOPS, and connection counts. Scaling should be a proactive decision, not a reactive one.
Common Pitfalls
- Ignoring the "Write Bottleneck": Adding 10 read replicas will help with read-heavy traffic, but it will do nothing to help if your primary database is struggling with too many writes. You must address write performance through sharding or database partitioning.
- Data Consistency Issues: In a distributed setup, read replicas are often "eventually consistent." If you update a record and immediately try to read it from a replica, you might get stale data. Ensure your application logic can handle this delay.
- Over-engineering: Don't implement sharding unless you absolutely have to. It introduces significant complexity to your application, complicates backups, and makes cross-shard joins nearly impossible.
Key Takeaways
- Vertical Scaling is upgrading the hardware of a single node. It is simple but limited by the maximum capacity of the hardware.
- Horizontal Scaling is adding more nodes to the cluster. It is complex to implement but allows for massive, near-infinite scale.
- Read Replicas are the most common first step for horizontal scaling in relational databases.
- Database optimization (indexing, query tuning) should always precede hardware scaling.
- Sharding is a powerful tool for scaling writes but should be considered a last resort due to the architectural complexity it introduces.
Reach the last section to complete this lesson and earn points — you're on section 1 of 4.
- Introduction to Azure Monitor
- Azure Monitor Architecture and Data Sources
- Configuring Log Analytics Workspaces
- Designing Log Routing Solutions
- Configuring Diagnostic Settings
- Application Insights for Solution Architects
- Network Watcher and Network Monitoring
- Azure Monitor Alerts and Action Groups
- Workbooks and Custom Dashboards
- Designing a Comprehensive Monitoring Strategy
- Logging and Monitoring Quiz5q
- Microsoft Entra ID for Solution Architects
- Designing Identity Solutions: B2B Collaboration
- Designing Identity Solutions: B2C Scenarios
- Conditional Access Policy Design
- Designing for Multi-Factor Authentication
- Managed Identities for Azure Resources
- Service Principals and App Registrations
- Role-Based Access Control Design
- Privileged Identity Management
- Microsoft Entra ID Protection
- Zero Trust Architecture with Microsoft Entra
- Authentication and Authorization Quiz5q
- Introduction to Azure Governance
- Designing Management Group Hierarchies
- Subscription Strategy Design
- Resource Group Organization Patterns
- Azure Policy Design and Assignment
- Custom Policy Definitions and Initiatives
- Resource Locks and Tagging Strategies
- Azure Blueprints and Landing Zones
- Cost Management and Budget Design
- Cloud Adoption Framework for Governance
- Governance Solutions Quiz5q
- Introduction to Azure Storage
- Storage Account Types and Replication
- Blob Storage Tiers and Lifecycle Management
- Azure Files and Azure NetApp Files
- Azure Managed Disks Design
- Azure Data Lake Storage Gen2
- Cosmos DB Consistency Models
- Cosmos DB Partitioning and Throughput Design
- Cosmos DB API Selection Guide
- Table Storage and Queue Storage Design
- Storage Security and Encryption
- Non-Relational Storage Quiz5q
- Azure SQL Database Service Tiers
- Azure SQL Managed Instance Design
- Azure Database for MySQL and PostgreSQL
- Database Scaling: Vertical and Horizontal
- Read Replicas and Geo-Replication
- Database Security and Auditing Design
- Transparent Data Encryption and Always Encrypted
- Caching with Azure Cache for Redis
- Azure SQL Elastic Pools Design
- Relational Storage Quiz5q
- Azure Data Factory Design Patterns
- Data Integration Pipeline Architecture
- Azure Synapse Analytics Design
- Azure Databricks Integration Patterns
- Azure Stream Analytics for Real-Time Data
- Azure Event Hubs for Data Ingestion
- Data Migration Strategies and Tools
- Azure Purview for Data Governance
- Data Integration Quiz5q
- Introduction to High Availability in Azure
- Availability Zones and Availability Sets
- Azure Load Balancer Design
- Application Gateway and WAF Design
- Azure Front Door and Global Load Balancing
- Azure Traffic Manager Routing Methods
- Multi-Region Architecture Design
- SLA Design and Composite SLAs
- Health Probes and Failover Configuration
- Azure Service Fabric for Stateful HA
- High Availability Quiz5q
- Azure Backup Architecture and Vaults
- Backup Policies for VMs and Databases
- Azure Site Recovery Design
- RTO and RPO Planning Strategies
- Geo-Redundant and Cross-Region Recovery
- Hybrid and On-Premises Backup Solutions
- Resiliency Patterns and Chaos Engineering
- Disaster Recovery Testing and Drills
- Azure Immutable Backup and Soft Delete
- Backup and Disaster Recovery Quiz5q
- Introduction to Azure Compute Options
- Virtual Machine Design and Sizing
- VM Scale Sets and Autoscaling Strategies
- Azure Batch for Large-Scale Workloads
- Azure App Service Plans and Design
- App Service Environments and Isolation
- Azure Container Instances
- Azure Kubernetes Service Architecture
- AKS Networking and Storage Design
- Azure Functions and Serverless Design
- Durable Functions and Orchestration
- Compute Decision Framework
- Azure Virtual Desktop Design
- Compute Solutions Quiz5q
- Microservices Architecture Patterns
- Azure API Management Design
- Azure Service Bus Messaging Design
- Azure Event Grid and Event-Driven Architecture
- Azure Event Hubs for Streaming
- Azure Logic Apps and Integration Workflows
- Azure SignalR and Web PubSub
- Caching Strategies and Azure CDN
- App Configuration and Feature Flags
- Designing for Scalability and Performance
- Azure Container Apps Design
- Application Architecture Quiz5q
- Virtual Network Design and Address Planning
- Subnet Design and Network Segmentation
- Hub-Spoke Network Topology
- Azure Virtual WAN Design
- VPN Gateway Design and Configuration
- ExpressRoute Circuit Design
- Network Security Groups Design
- Azure Firewall and Firewall Manager
- Azure DDoS Protection Design
- Private Endpoints and Private Link
- Azure DNS and DNS Architecture
- Network Performance and Traffic Routing
- Azure Bastion and Secure Access
- Network Solutions Quiz5q
- Azure Migrate Overview and Assessment
- Migration Assessment and Discovery
- Azure Cloud Adoption Framework for Migration
- VM Migration with Azure Migrate
- Database Migration with Azure DMS
- Application Migration to App Service
- Containerizing Applications for Migration
- Migration Cost Planning and Optimization
- Data Box and Offline Migration Methods
- Migrations Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons