Two database families: Relational vs NoSQL
Relational databases (MySQL, Postgres) store data in tables with fixed columns and explicit relationships (for example: Users, Chirps, Likes). They excel at joins and strict correctness guarantees and are queried with SQL:Relational systems: sharding via an extra layer
When you need SQL joins and relational guarantees at scale, you typically add a routing/resharding layer that presents a single SQL surface to the application and handles query routing and online resharding.Vitess (MySQL)
Vitess is a popular sharding/proxy layer originally built at YouTube (used by Slack and other large services). The application talks to Vitess as if it were a single MySQL instance; Vitess routes queries to the correct shard and handles online resharding for you.

Citus (Postgres)
Citus is a Postgres extension that exposes a single Postgres surface and distributes queries to the nodes that hold the relevant rows. If you shard related tables by the same key (for exampleuser_id), the relevant rows for a user (profile, posts, likes) can be co-located on one worker node so joins remain local and fast.

Citus supports copying small lookup/reference tables (e.g.,
country_codes) to every worker node. This is a standard optimization: replicate small, read-heavy tables to avoid cross-node joins.NoSQL systems: distribution built in
NoSQL systems typically embed the sharding logic inside the database and trade some cross-shard semantics for scalability and simpler operational models.Cassandra
Cassandra is a peer-to-peer distributed database: any node can accept a client request. The receiving node acts as a coordinator: it consults a consistent-hashing ring to determine which nodes own the data and forwards the request to them. There is no single primary machine.


DynamoDB
DynamoDB is a fully managed key-value / document store. Amazon runs the machines, handles partitioning, rebalancing, and splits. Your main responsibility is selecting the partition key (DynamoDB’s shard key).
- DynamoDB automatically splits and rebalances partitions as data grows.
- A single partition key value cannot be split across physical partitions; a very hot key (a single popular user) can become a throughput hotspot.
- Practical per-key limits (approximate for small items): ~3,000 small reads/s and ~1,000 small writes/s. Exact limits depend on item size and provisioned vs on-demand mode.
Design for per-partition limits. If one user or key becomes extremely popular (a “hot key”), you must mitigate with caching, request fanout, or by changing your data model (for example, adding time-based suffixes to keys or sharding at the application level).
MongoDB
MongoDB stores semi-structured documents and supports sharding via a router process (mongos). Data is split into ranges of shard key values called chunks. When chunks become imbalanced the balancer moves them between shards using the copy → catch-up → cut-over → delete lifecycle. Queries that include the shard key are targeted to a single shard:Quick comparison
Choosing a database and a shard key
Consider three main factors:- Query patterns to optimize: which queries must be low latency and single-shard?
- Required cross-shard consistency and joins: do you need relational transactions and joins, or can you denormalize?
- Operational model: do you prefer fully managed (DynamoDB, Atlas) or self-hosted control (Cassandra, Vitess/Citus)?
- Pick a shard key that makes the most common queries targeted (single-shard).
- Co-locate related tables on the same shard key in relational sharded systems (Vitess/Citus) to keep joins local.
- If you use a managed system (DynamoDB), design for per-key throughput limits and avoid hot keys.
- For NoSQL systems, adopt denormalized data models where joins would require scatter-gather behavior.
If your workload requires frequent multi-table joins and strong transactional guarantees, favor relational sharding layers (Vitess/Citus). If you need horizontal scale with simpler operational overhead or are building a high-throughput key-value service, consider NoSQL solutions but design for denormalization and hot-key mitigation.
Summary
- Relational systems (MySQL/Postgres) preserve SQL joins and stronger correctness; sharding is commonly provided by an external layer (Vitess for MySQL, Citus for Postgres).
- Cassandra and DynamoDB embed distribution: Cassandra is peer-to-peer with vnodes and coordinator routing; DynamoDB is fully managed and requires careful partition-key design.
- MongoDB shards by range and uses a router (mongos) with chunk migrations that follow the same online-migration steps.
- Choosing a database and shard key is always a tradeoff among query patterns, operational preferences, and the level of cross-shard semantics you need.