Senior Track Roadmap

Database sharding: horizontal

Horizontal sharding splits the rows of a table across several databases that share one schema. The course compares shards with replicas and explains the two problems sharding solves: write throughput and data volume. It covers choosing a shard key from access patterns, declaring shards with connects_to, and picking a shard at runtime with connected_to or the shard middleware. It then lists what sharding removes: joins, transactions, global uniqueness and cheap aggregates. It closes with the numbers that keep this application unsharded and a group_by_shard challenge.

What you'll learn

  • ✓How a shard differs from a replica and which problems each one solves
  • ✓Choosing a shard key that balances even distribution and query alignment
  • ✓Declaring shards in Active Record with connects_to shards:
  • ✓Selecting a shard per block or per request, including the shard swapping lock
  • ✓What sharding removes: joins, transactions, global uniqueness and cheap aggregates
  • ✓The alternatives to try before sharding, in order
Free preview · Lesson 1 3 min read

Splitting rows across databases

Horizontal sharding splits the rows of a table across several databases, each holding a different subset. Every shard has the same schema, and none of them has all the data.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...