Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
How Shopify Scales Rails
Search
John Duff
April 29, 2013
Technology
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How Shopify Scales Rails
This talk goes into detail about how Shopify has been using and scaling rails up to now.
John Duff
April 29, 2013
More Decks by John Duff
See All by John Duff
Scaling a Payments Platform
jduff
0
98
Riding Rails for 10 Years
jduff
0
40
Other Decks in Technology
See All in Technology
DBTS2026 盛り上がってますか!?Databricksが実現するAI時代のデータ基盤
akuwano
1
180
Kiro Crew 入門 (手を離しても進む仕事) | 目指せ Kiro マスター 11
inariku
PRO
3
420
Software Engineering in an AI-Driven World
erikjhordan_rey
0
120
【dbts2026】AIエージェントの 判断と探索を変える、 データベース エンジニアリング― 既存DBの処理と依存関係から作る、オペレーショナルオントロジー ―
shisyu_gaku
0
190
[General] 개발자로 해외 기업에서 일하기
skydoves
1
300
Don't write the architecture only in the prompt.
neohsu
0
310
HQ駆動開発で最高のAI-Contextを作ろう
sansantech
PRO
1
100
Maestro MCPとClaude Code Skillsによる自律的なE2Eテスト支援
asmz
0
420
E2Eってつらくないですか?E2Eの管理コストを下げる手段とその実践
akaboshinit
6
3k
Consistency for mere mortals - A gentle guide to consistency
ufried
0
120
Sinatra on PicoRuby ローカルでセルフホスト
bash0c7
0
100
Kiro Crew の Bot (続く役目を任せる窓口) | 目指せ Kiro マスター 12
inariku
PRO
1
270
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
660
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Paper Plane (Part 1)
katiecoart
PRO
2
12k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Building AI with AI
inesmontani
PRO
1
1.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
The SEO identity crisis: Don't let AI make you average
varn
0
630
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
610
The browser strikes back
jonoalderson
0
1.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Transcript
shopi fy How Shopify Scales Rails John Duff
What is Shopify?
None
None
None
The Stack
• Ruby 1.9.3-p327 • Rails 3.2 • Percona MySQL 5.5
• Unicorn 4.5 • Memcached 1.4.14 • Redis 2.6 The Stack
The Stack • 33 App Servers • 1172 Unicorn Workers
• 5 Job Servers • 370 Job Workers Nginx Unicorn Rails 3.2 Ruby 1.9.3- p327
The Stack Firewall Load Balancer App Servers Redis Job Servers
Database Memcached Search
• 55,873 Lines of application code • 81,892 Lines of
test code • 211 Controllers • 468 Models The Stack
Current Scale
9.9 M Orders An order every 3.2 seconds
2,008 Sales per Minute Cyber Monday
50,000 RPM 45 ms response time
13.3 billion requests
Looking Back, to Look Ahead
• First line of code written in 2004 • Shopify
released July, 2005 • Same codebase • Over 9 years of Rails upgrades, improvements and changes Looking Back, to Look Ahead
Looking Back, to Look Ahead • 6,702 Lines of application
code (55,873) • 4,386 Lines of test code (81,892) • 38 Controllers (211) • 77 Models (468)
Looking Back, to Look Ahead • Ruby 1.8.2 • Rails
0.13.1 • MySQL 4.1 • Lighttpd • Memcached
Know The System
One Request, One Process
RPM = W * 1/R
RPM = 1172 * 60 / 0.072
976,666 = 1172 * 60 / 0.072
↑ Workers ↓ Response Time
Know The System • Avoid network calls during requests •
Speed up unavoidable network calls • The Storefront and Checkout • The Chive
RPM Chive Flash Sale
Measure ALL THE THINGS
Measure ALL THE THINGS • New Relic • Splunk •
StatsD • Cacti • Conan
New Relic
Splunk
None
None
Caching
cacheable
cacheable • https://github.com/Shopify/cacheable • serve gzip’d content • generational caching
• no explicit expiry
cacheable class PostsController < ApplicationController def show response_cache do @post
= @shop.posts.find(params[:id]) respond_with(@post) end end def cache_key_data { :action => action_name, :format => request.format, :params => params.slice(:id), :shop_version => @shop.version } end end
requests Caching 404s
Identity Cache
Identity Cache • cache full model objects in memcached •
can include associated objects in cache • must opt in to the cache • explicit, but automatic expiry
Identity Cache class Product < ActiveRecord::Base include IdentityCache has_many :images
cache_index [:shop_id, :id] cache_has_many :images, :embed => true end @product = Product.fetch_by_shop_id_and_id(shop_id, id) @images = @product.fetch_images
Identity Cache
Get Out of My Process
Delayed Job • Jobs stored in the db • Workers
run in their own process • Workers poll for jobs periodically • https://github.com/collectiveidea/delayed_job
Resque • Redis backed • No more db contention •
Faster (300 jobs/sec vs 120 jobs/sec) • Extensible • https://github.com/defunkt/resque
Resque • Sending Email • Processing Payments • Geolocation •
Import / Export • Indexing for Search • 86 Other things...
Background Payment Processing ms
Resque class AddressGeolocationJob max_retries 3 def self.perform(params) object = params[:model].constantize.find(params[:id])
object.latitude, object.longitude = Geocoder.geocode(object) object.save! end end Resque.enqueue(AddressGeolocationJob, :id => 1, :model => 'Address')
Redis • Inventory reservation system • Sessions • Theme uploads
• Throttling • Sequenced Column
All Roads Lead To MySQL
MySQL Hardware • 4 x 8 Core Processor • SSD
• 256 GB Ram • Full working set in memory
MySQL Query Optimization • pt-query-digest • Avoid queries that generate
temp tables • Adding the right indexes • Forcing / Ignoring Indexes
MySQL Tuning • disable innodb_stats_on_metadata • increase table_open_cache • replace
glibc memory allocator with tcmalloc • innodb_autoinc_lock_mode=‘interleaved’
after_commit db transactions best friend
after_commit • After transaction has been committed • Webhooks •
Cache expiry • Update associated objects
after_commit class OrderObserver < ActiveRecord::Observer observe :order def after_save(order) if
order.changes.keys.include?(:financial_status) order.flag_for_after_commit(:update_customer) end end def after_commit(order) if order.flagged_for_after_commit?(:update_customer) Resque.enqueue(UpdateCustomerJob, :id => order.id) end end end
Services
Services • Split out standalone services as needed • Independently
scaled • Segmented metrics • Overall system is more complex • Limit to what is necessary
Imagery
Adapt and Evolve as Needed Using data and knowledge of
the system to drive decisions
Thanks. @johnduff |
[email protected]