Scaling Databases: Special Considerations
What you'll learn: Why databases require different scaling strategies than stateless application servers.
The Database Scaling Challenge
When you scaled your application servers horizontally, you simply added more identical machines behind a load balancer. Easy! But databases don't work the same way.
The fundamental problem: Databases must maintain data consistency. If User A updates their profile on Database Server 1, User B querying Database Server 2 must see that same update. This coordination is complex and expensive.
Why Vertical Scaling Comes First
With databases, you'll typically scale vertically before attempting horizontal scaling:
- Adding RAM improves caching (more data in memory = faster queries)
- Faster CPUs handle complex queries more efficiently
- Better storage (SSDs) reduces disk I/O bottlenecks
This buys you significant headroom without the coordination headaches of multiple database instances.
The Coordination Tax
Think of a single database like one librarian managing a catalog. They always know exactly which books are checked out. Now imagine ten librarians each with their own catalog — they must constantly communicate to stay synchronized. Every update means messages between all librarians. This coordination overhead is why horizontal database scaling is harder.
Stateless app servers don't have this problem because they don't "remember" anything between requests. Each handles a request independently. Databases, by definition, must remember and stay consistent.
Starting Point
When your database becomes a bottleneck, your progression typically looks like:
- Optimize queries and add indexes
- Scale vertically (bigger machine)
- Only then consider horizontal strategies (which we'll cover later)
Key Takeaway: Databases resist horizontal scaling because maintaining consistency across multiple database nodes requires complex coordination that stateless application servers don't face, making vertical scaling the natural first choice.