Partitioning and Replication Strategies

9 min read ยท Updated 2026-04-25

Database performance becomes critical when application user counts go from hundreds to millions. Successful operation under load depends on understanding how different database families scale and choosing the right approach for your workload.

This lesson is a tour of the main database families and how each one scales.

The Trade-offs to Balance

Read vs. write patterns
Read-heavy (content sites) vs. write-heavy (IoT data ingest). Different scaling strategies for each.
Vertical vs. horizontal
Bigger machines vs. more machines. Vertical is simpler; horizontal scales further but adds complexity.
Replication vs. sharding
Replication = multiple copies of all data (read scale + redundancy). Sharding = data split across nodes (write scale).
Consistency vs. performance
Strong consistency = synchronous coordination. Eventual consistency = faster, may serve stale data.

Relational Databases (Postgres, MySQL)

Modern Postgres and MySQL have evolved significantly โ€” supporting JSON documents, full-text search, and geospatial queries that used to require NoSQL. They remain the foundational data layer for most SaaS platforms.

Single-master architecture

Postgres uses a single-master architecture: all writes through one primary server, reads scale via streaming replication to multiple read replicas.

Strengths
What Postgres scales well at
Read-heavy workloads. Multiple replicas, each handling thousands of QPS at 10-50ms. ACID transactions. Mature SQL. Aurora-style separation of compute/storage extends this further.
Limitations
Where it hits walls
Write throughput is bounded by single primary. Vertical scaling has hard limits. Synchronous replication for full ACID becomes impractical when replicas slow down.

Scaling writes in relational databases

When write throughput maxes out a single primary:

Table partitioning
Postgres native partitioning by date or ID range. Single DB, multiple physical tables.
Citus, Vitess
Distribute tables across multiple nodes while preserving SQL semantics. Citus for Postgres, Vitess for MySQL. Tens of thousands of writes/sec.
Application-level sharding
Facebook-style: thousands of MySQL instances; app-level routing by user ID. Maximum control, maximum operational complexity.
Multi-leader replication
MySQL Group Replication, YugabyteDB. Multiple write nodes accept writes; conflict resolution required. Native or via add-ons (Postgres BDR, pglogical).

Document Stores (MongoDB)

MongoDB was built for horizontal scaling from day one. Sharded clusters distribute writes across multiple primaries simultaneously.

Architecture

[ Client ]
    โ”‚
    โ–ผ
[ mongos router ] โ”€โ”€ shard key lookup
    โ”‚
    โ”œโ”€โ–บ [ Shard A โ”€ Replica Set ]
    โ”œโ”€โ–บ [ Shard B โ”€ Replica Set ]
    โ””โ”€โ–บ [ Shard C โ”€ Replica Set ]

Wide-Column Stores (Cassandra)

Despite the name, โ€œwide-columnโ€ doesnโ€™t mean columnar storage. It means flexible row schemas where rows can have different columns. Internally, Cassandra is row-oriented.

Peer-to-peer architecture

   [ Client ]
       โ”‚
       โ–ผ
   [ Any node โ€” coordinator ] โ”€โ”€โ”
              โ”‚                  โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚  consistent hashing
   โ–ผ          โ–ผ          โ–ผ       โ”‚  โ†’ owner
 [Node 1]  [Node 2]  [Node 3]    โ”‚

No master. Every node is equal. Data distribution via consistent hashing. Any node can act as coordinator.

Optimized for writes
Append-only commit log + memtable + SSTable architecture. Tens of thousands of writes per second per node, predictable latency.
Multi-datacenter native
Tunable replication strategies across DCs. Each region can be a separate "rack" or DC. Strong fit for global apps.
Tunable consistency
Per-query: ANY, ONE, QUORUM, ALL. Choose latency vs. consistency for each operation.
Linear scalability
Add a node, capacity increases proportionally. Designed for massive scale (Netflix, Apple, Discord).

The cost: limited query flexibility (must design table layout per query pattern), no joins, eventual consistency by default.

Key-Value Stores (Redis, DynamoDB)

Simplest data model: keys map to values. The simplicity enables extreme scale and low latency.

Redis

In-memory key-value store. Sub-millisecond latency. Hugely versatile (strings, hashes, lists, sets, streams, pub/sub).

Used as cache, session store, real-time analytics, leaderboards, message queues.

DynamoDB

AWS-managed key-value with optional document features. Built on a Dynamo paper-style architecture.

Single-digit ms latency
Predictable performance at any scale. SLA-backed.
Effectively unlimited scale
AWS handles partition management, replication, scaling. You don't see infrastructure.
Pay-per-request or provisioned
On-demand mode for variable load; provisioned mode for predictable savings.
Global tables
Multi-region active-active replication built in. Compliance-friendly for global SaaS.

The cost: limited query patterns (must design access patterns up front), join-less, item size limits.

NewSQL: SQL Without the Single-Master Limit

A category that emerged to combine SQL semantics with horizontal scale.

Spanner / CockroachDB
Distributed SQL with strong consistency. Spanner uses TrueTime; CockroachDB uses HLC. Real ACID across regions.
YugabyteDB
Postgres-compatible distributed SQL. Multi-region active-active. Open source.
TiDB
MySQL-compatible distributed SQL. Strong fit for migrations from MySQL.
When to consider
When you need both SQL semantics and write throughput beyond a single Postgres can give. The operational tax is real โ€” adopt only when you actually need it.

Choosing for Multi-Tenant SaaS

A reasonable pattern for a SaaS platform:

Use caseDatabase choice
Tenant data, transactionalPostgres (with sharding or Aurora)
Tenant data, append-heavy time seriesCassandra or DynamoDB
User sessions, cachingRedis
SearchElasticsearch / OpenSearch
Analytics aggregatesClickHouse / BigQuery / Snowflake
Object storageS3

Most SaaS platforms run multiple databases โ€” each chosen for what itโ€™s best at. The pragmatic approach is โ€œuse the right database for the job,โ€ not โ€œforce everything into one.โ€

Recap