← Graph

Horizontal Sharding

concept 5 connections

Scaling technique where data is distributed across multiple databases that share the same schema. Natively supported in Rails since 6.1: shards are declared in database.yml (primary, primary_shard_one, …), models declare connects_to shards, and the app switches shard per request. Avoids the apartment gem's thread-safety problem because each shard has its own connection pool. Enables horizontal scaling beyond what a single database server can handle and supports compliance with data-sovereignty laws (e.g. storing European users' data in Europe). Requires ongoing attention to shard balancing to avoid the Noisy Neighbor problem.

category
architecture
about
Horizontal Sharding concept
Recommended as the native Rails 6.1 replacement for apartment-style database-per-tenant switching.
concept Horizontal Sharding
related_to
Natively supported in Rails since 6.1.
concept Horizontal Sharding
related_to
Shard balancing must account for noisy-neighbor effects.
tool Citus
related_to
Horizontal Sharding concept
Citus distributed tables implement horizontal sharding within Postgres.
related_to
Horizontal Sharding concept
CockroachDB auto-shards distributed data.

Provenance

Read by
5 extractions