---
title: "Horizontally scaling the Rails backend of Shop app with Vitess"
description: "Shop app outgrew a single MySQL database despite federating tables across databases, so the team moved its Rails backend to Vitess, sharding user-owned tables by user_id into a \"users\" keyspace and keeping the rest in an unsharded \"global\" keyspace."
url: "https://swe.quest/articles/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess-03c7b2da20f98ec3"
canonical: "https://shopify.engineering/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess"
source: "Shopify Engineering"
published: "2024-01-17"
difficulty: "medium"
kind: "Case study"
reading_minutes: 27
tags: ["mysql","distributed-databases","ruby","scalability","schema-migrations"]
---

# Horizontally scaling the Rails backend of Shop app with Vitess

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2024-01-17, 27 min read, Case study. Original: [https://shopify.engineering/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess](https://shopify.engineering/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess)

## Summary

Shop app outgrew a single MySQL database despite federating tables across databases, so the team moved its Rails backend to Vitess, sharding user-owned tables by user\_id into a "users" keyspace and keeping the rest in an unsharded "global" keyspace. The key enabler was a set of application-layer query verifiers that flagged missing sharding keys, cross-database and cross-shard transactions, cross-shard writes and cross-keyspace joins. They were rolled out first in dev/CI, then in log-only mode in production. Getting there also meant backfilling user\_id onto billion-row tables, rewriting shard-key updates as insert-then-delete, and patching ActiveRecord associations so the sharding key reaches every query. Two takeaways: fix the data model early, and avoid cross-shard transactions because Vitess does not roll back partial commits by default.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [MySQL](https://swe.quest/tags/mysql.md) (Data & databases)
- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Scaling](https://swe.quest/tags/scalability.md) (Distributed systems)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)

## Prerequisites

- MySQL basics ([easy posts on MySQL](https://swe.quest/tags/mysql.md?difficulty=easy))
- Rails ActiveRecord ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- database sharding concepts ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))

## Keywords

Vitess, Shop app, Ruby on Rails, ActiveRecord, VTGate, VTTablet, GhostFerry, KateSQL

## Related posts

- [Migrating Etsy’s database sharding to Vitess](https://swe.quest/articles/migrating-etsy-s-database-sharding-to-vitess-c6bef1d09f2cd679.md): Etsy Code as Craft · 2026-03-19 · Medium · 9 min read · MySQL, Distributed databases, Refactoring & migrations, SQLite, Deployment
  Etsy moved shard routing for its ~1,000-table, ~1,000-shard, 425 TB MySQL cluster (1.7M requests/sec) from an ORM that looked up random shard mappings in a single index database to Vitess vindexes, without moving any data.
- [Partitioning GitHub’s relational databases to handle scale](https://swe.quest/articles/partitioning-github-s-relational-databases-to-handle-scale-7b5ea75acfc088c0.md): GitHub Engineering · 2021-09-27 · Medium · 9 min read · MySQL, Distributed databases, Scaling, Schema migrations, Ruby
  GitHub split its monolithic \`mysql1\` MySQL cluster by first virtually partitioning tables into schema domains (declared in YAML) and enforcing boundaries with query and transaction linters, then physically moving domains to new clusters via Vitess vertical sharding or a custom ProxySQL/GTID-based write-cutover script.
- [Handling hot shards](https://swe.quest/articles/handling-hot-shards-713450434ac73606.md): PlanetScale · 2026-09-28 · Medium · 7 min read · Distributed databases, PostgreSQL, Scaling, Multi-tenancy
  When a shard key like tenant\_id stops matching reality because a few whale tenants dominate load or cross-tenant queries appear, Neki (PlanetScale's sharded Postgres from the Vitess maintainers) offers three escalating fixes: vertically scale the hot shard with its own configuration profile, isolate the whale by narrowing hashed key ranges in the declarative data topology, or reshard specific tables by a better key.
- [Shard design doesn't start from your tables](https://swe.quest/articles/shard-design-doesn-t-start-from-your-tables-283c900085b220b2.md): PlanetScale · 2026-10-23 · Medium · 8 min read · Distributed databases, PostgreSQL, System design
  Neki's shard groups co-locate related Postgres tables by hashing a shared shard key (e.g. customer\_id via xxhash) into a 64-bit keyspace split across shards, so joins and transactions for one customer stay on a single shard with full Postgres semantics.
- [Shard Balancing: Moving Shops Confidently with Zero-Downtime at Terabyte-scale](https://swe.quest/articles/shard-balancing-moving-shops-confidently-with-zero-downtime-at-terabyte-scale-76a6177fa357eea4.md): Shopify Engineering · 2021-09-24 · Medium · 13 min read · MySQL, Distributed databases, Schema migrations, Scaling
  Shopify rebalances its MySQL shards by moving individual shops between pods online, with downtime confined to a brief cutover.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
