Scalability and Data Modeling in Databases
Database scalability isn’t just about handling more data — it’s about maintaining performance, reliability, and reasonable cost as the system grows. Real database choices involve fundamental trade-offs between consistency, performance, and complexity.
This lesson is the framework for evaluating database choices: workload patterns first, then data model, then scaling approach.
The Forces in Tension
Relational Databases — Still the Default
Predictability is the strength. The schema is upfront and explicit. SQL is one of the most powerful query languages ever designed.
Modern Postgres and MySQL have evolved past the “NoSQL killers” — they support JSON documents, full-text search, geospatial, time-series. For most SaaS apps, start with Postgres.
Scaling reads
Postgres is single-master for writes; reads scale via streaming replication. Multiple read replicas at 10-50ms latency, thousands of QPS each.
Scaling writes
Single-master is the constraint. Options:
- Vertical scaling — bigger box. Postgres can handle huge workloads on serious hardware. Don’t underestimate this.
- Read offload — move heavy reads off the primary. Replicas, materialized views, OLAP DBs.
- Sharding — Citus, Vitess, or app-level. Significantly more complex; reach for it when you’ve genuinely outgrown a single Postgres.
- NewSQL — CockroachDB, Spanner, YugabyteDB. SQL with horizontal write scale, at operational cost.
If a synchronous replica is down or lagging, the commit waits for that replica. Most deployments replicate asynchronously and, when a caller must see its own write, send that read to the primary.
Multi-leader writes (MySQL Group Replication, Oracle, SQL Server, YugabyteDB, or add-ons such as EDB Postgres Distributed and pglogical) push conflicts into the application. Autoincrement keys, triggers, and integrity constraints collide when two leaders accept overlapping updates, and every overlap needs an explicit resolution rule. Large MySQL estates instead route by user id across many single-leader shards.
Document Databases (MongoDB)
Designed for horizontal scaling from day one. Sharded clusters distribute writes across multiple primaries.
Each shard is its own replica set, and one node can be primary for one shard while secondary for another. mongos is a stateless router: it reads the shard key, forwards the write to that shard’s primary, and scatter-gathers when a query spans shards. Write throughput tracks the number of shard primaries. A hot user, a monotonic timestamp, or a low-cardinality tenant as the shard key piles writes onto one primary. Tuned clusters in this shape commonly sustain thousands of writes per second at roughly 10-100 ms.
Wide-Column Stores (Cassandra, ScyllaDB)
Peer-to-peer architecture, no master. Optimized for massive write throughput and multi-DC.
The cost: limited query flexibility (must design table layout per query pattern), no joins, eventual consistency by default.
Any node can coordinate. Consistent hashing names the owners, and that node writes locally or forwards. Adding a node adds both read and write capacity. Netflix has described Cassandra clusters above 200,000 writes per second with median latency around 1-2 ms. Acknowledge one replica on the ingest path, or a majority when that read cannot be stale.
Key-Value Stores
Time-Series Databases
Specialized for high-volume time-stamped data — IoT sensors, monitoring metrics, financial ticks.
A TimescaleDB hypertable looks like one table and is stored as time chunks: recent chunks stay uncompressed, older chunks are compressed, and queries stay ordinary SQL. Cloudflare has ingested about 100,000 aggregated metrics per second this way.
Search Databases
For full-text search, complex filtering, log analysis.
Analytics / OLAP
OLTP databases optimize for many small transactions. OLAP databases optimize for few large analytical queries scanning massive amounts of data.
Columnar layout stores one column together, so a sum over revenue reads that column and skips the rest, often about a tenfold I/O cut versus full rows. A single ClickHouse server can process on the order of 2 billion rows per second for a simple aggregation, and log scans of hundreds of millions of rows are reported under 200 ms. Ingest is append-only, often from Kafka.
Druid rolls data up at ingest. Real-time nodes take the stream, historical nodes serve sealed segments, and brokers cache the merged answer, so a declared rollup can return in under 100 ms. A materialized view is the relational version of that trade: store the aggregate and turn a multi-second query into a 10-100 ms lookup.
Graph Databases
For relationship-heavy data: knowledge graphs, fraud detection, recommendation engines.
- Neo4j — the dominant property-graph DB. Cypher query language.
- Amazon Neptune — managed graph DB on AWS. Property graph (Gremlin) and RDF (SPARQL).
- JanusGraph — distributed graph DB on top of Cassandra/HBase.
NewSQL: SQL Without the Single-Master Limit
A category that emerged to combine SQL with horizontal scale.
Choosing for Your Workload
A pragmatic decision tree for SaaS apps:
| Use case | Default choice |
|---|---|
| Tenant-scoped transactional data | Postgres (Aurora at scale) |
| User sessions, caching, rate limits | Redis |
| Search, full-text, log analysis | Elasticsearch / OpenSearch |
| Time-series metrics | Timescale or InfluxDB |
| Analytics warehouse | Snowflake / BigQuery / Redshift |
| Object storage | S3 |
| High-throughput append-only | Kafka + DynamoDB / Cassandra |
| Distributed multi-region OLTP | CockroachDB / Spanner |
Most production SaaS platforms run multiple databases, each tuned for what it’s best at. The “one database to rule them all” pattern doesn’t survive scale.
Recap
- Database scalability is about workload patterns first, data model second, scaling approach third.
- Relational (Postgres, MySQL) is the right default for most SaaS — modern features cover most NoSQL use cases.
- Document, wide-column, key-value, time-series, search, analytics, graph — each shines in specific use cases.
- NewSQL (Spanner, CockroachDB) gives you SQL with horizontal write scale, at operational cost.
- Real systems use multiple databases. The skill is matching access patterns to database strengths, not picking one for everything.