Skip to content
MartianChronicles
  • Home
  • Articles
  • Series
  • Projects
  • Resources
  • About
  • Search
Portfolio
MartianChronicles

Exploring Software, AI and Ideas Beyond Code

Explore
  • Articles
  • Series
  • Projects
  • Resources
GitHubLinkedInDev.toEmail

© 2026 Niraj Mourya. All rights reserved.Built with Next.js, React, Material UI
  1. Home
  2. /
  3. Articles
  4. /
  5. Database Scaling Fundamentals

Database Scaling Fundamentals
Engineering
#databases
#system-design
#scalability
#backend
#distributed-systems

Database Scaling Fundamentals

Learn the fundamentals of database scaling, including vertical scaling, horizontal scaling, replication, sharding, indexing, caching, and the CAP theorem.

Author

Niraj Mourya

Published

July 8, 2026

Updated

July 8, 2026

Reading Time

5 min read

Table of Contents

On this page

31 sections


  • Vertical vs Horizontal Scaling
  • Vertical Scaling (Scale Up)
  • Advantages
  • Limitations
  • Horizontal Scaling (Scale Out)
  • Advantages
  • Challenges
  • Database Replication
  • Why Replicate?
  • Primary–Replica Architecture
  • Synchronous Replication
  • Asynchronous Replication
  • Typical Use Cases
  • Database Sharding
  • Why Shard?
  • Sharding Strategies
  • Range-Based Sharding
  • Hash-Based Sharding
  • Geo-Based Sharding
  • Typical Use Cases
  • Replication vs Sharding
  • Database Indexing
  • Advantages
  • Trade-offs
  • Read–Write Splitting
  • CAP Theorem
  • Caching
  • Putting Everything Together
  • Key Takeaways
  • References
  • Continue Reading

Jump to section

On this page

31 sections

As applications grow, adding more application servers is only part of the scalability story.

In most production systems, the database becomes the bottleneck long before the application code does.

Understanding concepts such as replication, sharding, indexing, caching, and the CAP theorem is essential for designing reliable, scalable systems.

In this article, we'll explore each of these concepts and understand when to use them.


Vertical vs Horizontal Scaling

Before discussing distributed databases, it's important to understand how applications scale.

Vertical Scaling (Scale Up)

Vertical scaling means increasing the capacity of a single server.

Examples include:

  • More CPU cores
  • More RAM
  • Faster SSD storage

Advantages

  • Simple to implement
  • No architectural changes
  • Easy operational management

Limitations

  • Hardware has physical limits
  • Costs increase rapidly
  • Creates a single point of failure

Vertical scaling is often the fastest solution during the early stages of a product, but eventually reaches hardware limits.


Horizontal Scaling (Scale Out)

Horizontal scaling adds more servers instead of making one server larger.

Instead of:

TEXT
11 Large Database Server

You move towards:

TEXT
110 Smaller Database Servers

Advantages

  • Virtually unlimited scalability
  • Better fault tolerance
  • Higher availability

Challenges

  • Increased operational complexity
  • Distributed system challenges
  • Network communication overhead

Horizontal scaling introduces concepts like Replication and Sharding.


Database Replication

Replication creates multiple copies of the same data across different database servers.

Why Replicate?

Replication helps achieve:

  • Higher read throughput
  • Better availability
  • Disaster recovery
  • Fault tolerance

Primary–Replica Architecture

TEXT
1          Primary (Writes)2               │3      ┌────────┴────────┐4      │                 │5 Replica 1         Replica 2

Typically:

  • All writes go to the Primary.
  • Read traffic is distributed across Replicas.

Synchronous Replication

The Primary waits until replicas acknowledge the write.

Advantages

  • Strong consistency

Disadvantages

  • Higher write latency

Asynchronous Replication

The Primary immediately acknowledges the write without waiting.

Advantages

  • Faster writes
  • Better throughput

Disadvantages

  • Replication lag
  • Eventual consistency

Asynchronous replication may briefly expose stale data because replicas can lag behind the primary.


Typical Use Cases

Replication is commonly used in:

  • News websites
  • E-commerce platforms
  • Social media feeds
  • Analytics dashboards

Database Sharding

Replication copies data.

Sharding divides data.

Instead of storing every record in one database, data is partitioned across multiple databases.

Example:

TEXT
1Shard A → Users 1–1M23Shard B → Users 1M–2M45Shard C → Users 2M–3M

Each shard owns only a subset of the data.


Why Shard?

Sharding helps:

  • Scale writes
  • Handle massive datasets
  • Remove database bottlenecks

Sharding Strategies

Range-Based Sharding

TEXT
1User ID 1–1000     → Shard A23User ID 1001–2000  → Shard B

Advantages

  • Simple

Disadvantages

  • Can create hotspots

Hash-Based Sharding

TEXT
1hash(user_id) % N

Advantages

  • Better load distribution

Disadvantages

  • Difficult to rebalance

Geo-Based Sharding

TEXT
1US Users → US Database23EU Users → EU Database45APAC Users → APAC Database

Useful for:

  • Reduced latency
  • Data residency
  • Regulatory compliance

Typical Use Cases

  • Messaging systems
  • Large SaaS platforms
  • Social networks

Replication vs Sharding

FeatureReplicationSharding
DataCopiedPartitioned
Primary BenefitRead scalabilityWrite scalability
ComplexityModerateHigh
AvailabilityHighModerate
Typical Use CaseHigh availabilityMassive datasets

Replication and sharding solve different problems and are often used together in large-scale systems.


Database Indexing

Without an index, a query such as:

SQL
1SELECT2WHERE

requires scanning every row.

With an index, the database can directly locate the matching record.

Advantages

  • Faster lookups
  • Better query performance

Trade-offs

  • Slower writes
  • Additional storage
  • Index maintenance

Indexes improve read performance but are not free.


Read–Write Splitting

Replication often enables Read–Write splitting.

TEXT
1Application23├── Writes → Primary45└── Reads  → Replicas

Benefits:

  • Reduces Primary load
  • Improves read throughput

Challenges:

  • Replication lag
  • Eventual consistency

CAP Theorem

A distributed system cannot simultaneously guarantee:

  • Consistency
  • Availability
  • Partition Tolerance

During a network partition, a system must choose between:

  • Consistency
  • Availability

Most large-scale internet systems prioritize:

  • Availability
  • Partition Tolerance

and therefore accept eventual consistency.

The CAP Theorem deserves its own deep dive. We'll cover it in a dedicated article.


Caching

Sometimes the best database optimization is avoiding the database altogether.

Popular caching technologies include:

  • Redis
  • Memcached

Typical use cases:

  • Session storage
  • Frequently accessed queries
  • API responses
  • Rate limiting

Caching significantly reduces database load and improves response times.


Putting Everything Together

Modern large-scale systems often combine multiple strategies:

  • Replication for read scalability
  • Sharding for write scalability
  • Indexing for query performance
  • Caching to reduce database load

There is no single solution that solves every scalability problem.

Good architecture combines these techniques based on system requirements.


Key Takeaways

  • Vertical scaling is simple but limited.
  • Horizontal scaling enables long-term growth.
  • Replication improves read scalability and availability.
  • Sharding improves write scalability.
  • Indexes speed up reads while increasing write costs.
  • Caching reduces database load.
  • The CAP Theorem forces trade-offs in distributed systems.

References

  • Designing Data-Intensive Applications — Martin Kleppmann
  • Database Internals — Alex Petrov
  • High Performance MySQL
  • PostgreSQL Documentation
  • Redis Documentation

Continue Reading

  • CAP Theorem (Coming Soon)
  • Consistent Hashing (Coming Soon)
  • Load Balancing Strategies (Coming Soon)
  • Microservices vs Monolithic Architecture

Tags, Topics & Technologies

database-scaling
distributed-systems
PostgreSQL
MySQL
Redis
Previous Article

Engineering Calm Systems

Read previous
Next Article

Placeholder next article

Related Articles
  • Load Balancing Fundamentals
  • Microservices vs Monolithic Architecture
  • Engineering Calm Systems
Share
LinkedInX

Published on Martian Chronicles