---
title: "Horizontally scaling the Rails backend of Shop app with Vitess"
description: "Shop app’s hockey-stick growth pushed its Ruby on Rails backend and MySQL primary datastore toward capacity, with multi-terabyte storage, week-long schema migrations, and throttled background jobs. After splitting databases and scaling surrounding systems, the team adopted Vitess to shard and re-shard MySQL while retaining SQL compatibility and self-managed primary datastores. They organized user-owned data into a sharded “users” keyspace using user_id, kept other data in an unsharded “global” keyspace, and built application-layer query verifiers to validate routing, distribution, and transaction correctness before migration. The move made schema migrations take hours instead of weeks, removed the reported capacity-driven throttling, and enabled further scaling by adding shards, while introducing concepts such as Sequences, Vindexes, and VSchemas that developers must learn."
---

# Horizontally scaling the Rails backend of Shop app with Vitess

[Shopify](https://yomu.fyi/company/shopify) · 2023-10-18 · Jan 17, 2024

**Type:** Problem & solution

## Summary

Shop app’s hockey-stick growth pushed its Ruby on Rails backend and MySQL primary datastore toward capacity, with multi-terabyte storage, week-long schema migrations, and throttled background jobs. After splitting databases and scaling surrounding systems, the team adopted Vitess to shard and re-shard MySQL while retaining SQL compatibility and self-managed primary datastores. They organized user-owned data into a sharded “users” keyspace using user\_id, kept other data in an unsharded “global” keyspace, and built application-layer query verifiers to validate routing, distribution, and transaction correctness before migration. The move made schema migrations take hours instead of weeks, removed the reported capacity-driven throttling, and enabled further scaling by adding shards, while introducing concepts such as Sequences, Vindexes, and VSchemas that developers must learn.

## Context

Hockey-stick growth after the Shop app launched pushed its Ruby on Rails backend and MySQL primary datastore toward their limits. The database had grown to many terabytes, schema migrations took weeks, and background jobs were throttled when database capacity was strained. Further database splitting would have increased application complexity and required cross-database transactions.

## Approach / What changed

The team selected Vitess, an open-source database system abstraction over MySQL, to support sharding, coordinated schema migrations, connection pooling, and SQL-compatible access. They chose user\_id as the sharding key, divided data between sharded users and unsharded global keyspaces, reorganized tables to include user\_id, and built application-layer query verifiers for routing, distribution, and transaction correctness.

## Takeaways

- User-owned data was placed in a sharded “users” keyspace using user\_id, while other data remained in an unsharded “global” keyspace.
- Application-layer query verifiers checked query correctness, shard routing, data distribution, and risks from cross-shard queries or partially committed transactions.
- Vitess reduced schema migration time from weeks to hours and enabled further scaling by adding shards, but required developers to understand Sequences, Vindexes, and VSchemas.

**Tags:** [Migrations](https://yomu.fyi/topic/migration), [MySQL](https://yomu.fyi/topic/mysql), [Performance](https://yomu.fyi/topic/performance), [Scalability](https://yomu.fyi/topic/scalability), [Testing](https://yomu.fyi/topic/testing)

- Source: [Shopify](https://shopify.engineering/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess)
- Source URL: https://shopify.engineering/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess
- Ingested by Yomu: 2026-08-30T13:20:41.203Z

[Read original post](https://shopify.engineering/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess)
