# How to Introduce Composite Primary Keys in Rails

DevFeed: [How to Introduce Composite Primary Keys in Rails](<https://devfeed.tech/articles/how-to-introduce-composite-primary-keys-in-rails-1422.md>)

Original publisher: [Read original article](<https://shopify.engineering/how-to-introduce-composite-primary-keys-in-rails>)

Author: John Arthorne

Published: 2020-10-29T19:00:36Z

Content type: tutorial

Language: en

Sources: [Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering.md>), [Shopify Engineering - Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering-shopify-engineering.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [MySQL](<https://devfeed.tech/topics/mysql.md>), [Multitenancy](<https://devfeed.tech/topics/multitenancy.md>), [Scalability](<https://devfeed.tech/topics/scalability.md>), [Architecture & Design](<https://devfeed.tech/topics/architecture-design.md>)

Tags: [architecture](<https://devfeed.tech/tags/architecture.md>), [code](<https://devfeed.tech/tags/code.md>), [database](<https://devfeed.tech/tags/database.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [performance](<https://devfeed.tech/tags/performance.md>), [rails](<https://devfeed.tech/tags/rails.md>), [scalability](<https://devfeed.tech/tags/scalability.md>), [shopify](<https://devfeed.tech/tags/shopify.md>)

## AI overview

This Shopify engineering article explains how composite primary keys can improve data locality and query performance in a Rails application with a multi-tenant database architecture. It discusses how auto-incrementing primary keys interleave records from different shops, while queries commonly access one shop at a time, and introduces the relevant MySQL InnoDB storage concepts, including B+ trees and pages.

## Source excerpt

One line of code can 5x your Rails application performance. What if you could make a small change to your database design that would unlock massively more efficient data access? At Shopify, we dusted off some old database principles and did exactly that with the primary Rails application.