SlideShare a Scribd company logo
Hosting Ruby Web
Apps
Lessons learned from 8 years of
Overview
• System architecture
• Initial setup & deploy
• Keep it running and moving forward
Michael Reinsch
michael@doorkeeper.jp
@mreinsch
Next Weekend!
startupweekend.jp/swtokyo-personal-cloud/
Michael Reinsch
michael@doorkeeper.jp
@mreinsch
Build a community through your events.
Hosting Ruby Web Apps
DB
(psql)
memcache
nginx
unicorn
unicornRails App
(unicorn)
job worker
MTA
(postfix)
Contenders
Contenders
Contenders
Contenders
Contenders
Please Note
• Not an exhaustive list of all hosting providers

(it’s not even everyone we’ve been using)
• Moving targets
Choosing Server Size
www.flickr.com/photos/jonrb/7864016624
Choosing Server Size
• good CPU performance
• choose 2GB RAM or more
Choosing Server Size
• 1 ECU/core is a bit frustrating
• 2 ECU/core is OK
• >2 ECU/core is better
Choosing Server Size
• 3 different sizes
• choose standard size if you don’t
have specific requirements
Hardware Failures
How can we make things robust?
www.flickr.com/photos/doegox/4551458930
Hardware Failures
“We’re trying to prevent failures, please
make backups for worst case”
!
• provides load balancer
• fault tolerant setup example:

2 web instances + 2 DB instances
• need to configure DB replication and
failover yourself
Hardware Failures
“Failures will happen, build your infrastructure
so they won’t impact you”
• provides load balancer (ELB)
• provides managed DB instances (RDS)
• replication support (not for psql yet)
• DB snapshots (can’t download though)
• fault tolerant setup example: 

2 web instances + multi-AZ RDS
Hardware Failures
“Failures will happen, let us help you build an
infrastructure so they won’t impact you”
• HA proxy on web instances
• one-click setup for DB (mysql/psql)
• replication support
• DB snapshots (downloadable)
• fault tolerant setup example:

2 web instances + 2 DB instances
Hardware Failures
“You don’t need to worry about failures”
!
!
• everything managed
• fault tolerant setup example:

2 dynos + premium DB (psql)
Initial Setup & Deploy
www.flickr.com/photos/thedailyenglishshow/6013713229
Initial Setup & Deploy
• manual setup feasible:
• install OS, ruby (rvm), libs, DB
• setup nginx
Initial Setup & Deploy
• let’s choose Capistrano for deploying
• Capistrano config goes into source
repository
• Initial deploy:
cap deploy:setup

cap deploy:cold
Initial Setup & Deploy
• let’s choose OpsWorks
• based on chef, provides predefined
set of recipes
• more high level than Cloud Formation,
more flexible than Elastic Beanstalk
Initial Setup & Deploy
• initial deploy:
• create stack
• define layers
• create instances
• create app
• deploy
Initial Setup & Deploy
• define base layer
• assign it to all instances
• use it for any common recipes like
creating swap, NewRelic, ...
Tip
Initial Setup & Deploy
• you need to handle asset compilation
• use deploy hook:
Tip
# deploy/before_migrate.rb
!
rails_env = new_resource.environment["RAILS_ENV"]
Chef::Log.info("Precompiling assets for RAILS_ENV=#{rails_env}...")
!
execute "rake assets:precompile" do
cwd release_path
command "bundle exec rake assets:precompile"
environment "RAILS_ENV" => rails_env
end
!
!
Initial Setup & Deploy
• provides toolchain based on chef
• initial deploy:
• create an application
• select environment layout
• add plugins (NewRelic, ...)
• deploy
Initial Setup & Deploy
Heroku comes with its’ own toolchain:
heroku create my-awesome-app

heroku addons:add …

git remote add heroku …

git push heroku master
What you’ll probably also
need
• App configuration 

(for secrets and endpoints)
• Sending email
• Job queue
App Configuration
• no predefined way: DIY
• put settings.yml into shared config dir
• link it into app when deploying
App Configuration
• uses environment variables
heroku config:add MY_SECRET=topsecret

heroku config
• in your code:
ENV[‘MY_SECRET’]
Sending Email
• use an email sending service

(SendGrid, AWS SNS)
• EY and Heroku provide plugins for
easy installation
Sending Email Yourself
• reverse IP lookup
• port 25 is restricted
• make sure your IP isn’t blacklisted
Job Queue
• DIY
• define custom layer in OpsWorks,
need to get 3rd party recipe
Job Queue
• sample recipes are provided
• worker instances
Job Queue
• provides worker dynos
• requires setup in Procfile
Background
mailer
• use database transaction to atomically create
mailer job and related data
• rollback if something goes wrong
• reduces request response time
• job can retry sending email
Tip
Up and running :-)
Continuous Deployment
www.flickr.com/photos/layos/3743880081
Continuous Deployment
• keep deploys cheap
• automate deploy
• easy deployment trigger
• good test coverage - use CI
• use rolling / zero downtime deploy
Continuous Deployment
• deploy command:
git pull

cap deploy
• unicorn for rolling deploy
Continuous Deployment
• unicorn is configured for rolling
deploys
• deploy command:
aws --region=‘us-east-1’

opsworks create-deployment

--stack-id=‘<STACK_UUID>’

--app-id=‘<APP_UUID>’

--instance-ids=‘[“<INSTANCE_UUID>”]’

--command='{"Name": "deploy"}
Continuous Deployment
gem 'aws-sdk'
gem 'parseconfig'
!
PRODUCTION_APP_ID = "09afbde1-322b-4816-a1e9-xxxxxxxxxxxx"
!
config = ParseConfig.new(File.expand_path("~/.aws/config"))
AWS.config(
:access_key_id => config['default']['aws_access_key_id'],
:secret_access_key => config['default']['aws_secret_access_key'])
!
@ops = AWS::OpsWorks.new.client
@ops_app = @ops.describe_apps(app_ids: [PRODUCTION_APP_ID])[:apps].first
@ops_stack = @ops.describe_stack_summary(stack_id: @ops_app[:stack_id])[:stack_summary]
@ops_inst = @ops.describe_instances(stack_id: @ops_app[:stack_id])[:instances]
@ops_inst_ids = @ops_instances.map do |instance|
instance[:instance_id] if instance[:status] == 'online'
end.compact
!
puts "Deploying #{@ops_app[:name]} to #{@ops_stack[:name]}"
!
deploy_options = {
command: { name:' deploy' },
comment: "deploy from #{Socket.gethostname}",
stack_id: @ops_app[:stack_id],
app_id: @ops_app[:app_id],
instance_ids: @ops_inst_ids }
@ops.create_deployment deploy_options
!
!
or some simple ruby script:
Continuous Deployment
• deploy command:
ey deploy
• in config/ey.yml:
maintenance_on_migrate: false
Continuous Deployment
• deploy command:
git pull

git push heroku master
• no-downtime deploys experimental:
heroku labs:enable -a myapp preboot
Continuous Deployment
• “fork” in code
• on/off switch for features
• slow rollout of new features
Tip
Rolling Deploys with!
Database Migrations
www.flickr.com/photos/edwardshousemovers/6704586649
Rolling Deploys with
Database Migrations
orchestrated deployment flow:
1. copy code, keep old version
2. run migrations
3. switch to new code
➜ one-step deployments
Rolling Deploys with
Database Migrations
• asynchronous deployment flow
• two-step deployment
1. deploy old code + DB migrations

(one instance only)
2. deploy new code

(all instances)
Rolling Deploys with
Database Migrations
• migrations are run via:
heroku run rake db:migrate
• two-step deployment
1. deploy old code + DB migrations
2. deploy new code
Down for!
Maintenance
www.flickr.com/photos/metrolibraryarchive/4128611963
Down for Maintenance
• Maintenance page done right:
• include contact and progress info

(use 3rd party service like Twitter)
• serve page with 503 error code
• use asset host or inline all assets
Tip
Down for Maintenance
• add ‘capistrano-maintenance’ gem
• configure nginx
• then:
cap maintenance:enable
server { // nginx server config
!
location @maintenance {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
if (-f $document_root/system/maintenance.html) { return 503; }
!
error_page 503 @maintenance;
Down for Maintenance
• Need custom recipe / script
• Can use similar approach as with
Capistrano
• 503 won’t pass ELB health check!
• Alternative: use Route53 to fail over to
instance serving maintenance page
Down for Maintenance
• Part of the platform:
ey web disable
heroku maintenance:on
Getting Support
Getting Support
• provides ticket system for any
platform related issues
• forum for anything else
Getting Support
• forums for everything
• access to tickets only available if
certain health checks fail
Getting Support
• tickets for everything
• provides even hosting related help on
application level
• “extension of your team”
Conclusion
• there is no silver bullet
• a lot depends on your app
• be ready to get your hands dirty
• your production environment is your
app
• balance ops / dev
Thank you!
Contact:
Michael Reinsch

michael@doorkeeper.jp

@mreinsch
Questions?
More awesome events:
• ijaws.doorkeeper.jp
• Startup Weekend Tokyo Personal Cloud

More Related Content

PDF
Inside the Chef Push Jobs Service - ChefConf 2015
PDF
Mitchell Hashimoto, HashiCorp
PDF
Chef Fundamentals Training Series Module 1: Overview of Chef
PPTX
Zero Code Multi-Cloud Automation with Ansible and Terraform
PPTX
Distributed automation sel_conf_2015
PDF
Puppet in the Pipeline
PDF
Introduction to Chef - April 22 2015
PDF
Introduction to Chef - Techsuperwomen Summit
Inside the Chef Push Jobs Service - ChefConf 2015
Mitchell Hashimoto, HashiCorp
Chef Fundamentals Training Series Module 1: Overview of Chef
Zero Code Multi-Cloud Automation with Ansible and Terraform
Distributed automation sel_conf_2015
Puppet in the Pipeline
Introduction to Chef - April 22 2015
Introduction to Chef - Techsuperwomen Summit

What's hot (20)

PPTX
Immutable Infrastructure with Packer Ansible and Terraform
PDF
Learning chef
PPTX
What's new in chef 12
PDF
Compliance as Code
PPTX
Scaling and Managing Selenium Grid
PDF
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
PPTX
Understand Chef
PDF
Push jobs: an orchestration building block for private Chef
PDF
Using SaltStack to DevOps the enterprise
PPTX
Infrastructure as Code
PPTX
Autoscaled Distributed Automation using AWS at Selenium London MeetUp
PDF
The way to set automation testing
PDF
Ansible and AWS
PPTX
SAP TechEd 2013 session Tec118 managing your-environment
PPTX
Automating aws infrastructure and code deployments using Ansible @WebEngage
PPTX
Infrastructure modeling with chef
PDF
Chef ignited a DevOps revolution – BK Box
PDF
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
PPTX
Infrastructure Automation with Chef & Ansible
PDF
TIAD : Automating the aplication lifecycle
Immutable Infrastructure with Packer Ansible and Terraform
Learning chef
What's new in chef 12
Compliance as Code
Scaling and Managing Selenium Grid
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
Understand Chef
Push jobs: an orchestration building block for private Chef
Using SaltStack to DevOps the enterprise
Infrastructure as Code
Autoscaled Distributed Automation using AWS at Selenium London MeetUp
The way to set automation testing
Ansible and AWS
SAP TechEd 2013 session Tec118 managing your-environment
Automating aws infrastructure and code deployments using Ansible @WebEngage
Infrastructure modeling with chef
Chef ignited a DevOps revolution – BK Box
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Infrastructure Automation with Chef & Ansible
TIAD : Automating the aplication lifecycle
Ad

Similar to Hosting Ruby Web Apps (20)

PPTX
Ansible: How to Get More Sleep and Require Less Coffee
PPTX
Moving Windows Applications to the Cloud
PDF
Getting to Walk with DevOps
PPTX
Ansible presentation
PPTX
ansible-app-platforme-2024-presentation-
PPTX
Ansible benelux meetup - Amsterdam 27-5-2015
PPTX
Power of Azure Devops
PDF
Continuous Delivery: How RightScale Releases Weekly
PDF
PyCon India 2012: Celery Talk
PDF
Stress Free Deployment - Confoo 2011
PPTX
Auto Deploy Deep Dive – vBrownBag Style
PDF
Training Slides: 103 - Basics - Simple Tungsten Clustering Installation
PPTX
NSBCon UK nservicebus on Azure by Yves Goeleven
PDF
OpenStack Deployments with Chef
PDF
Automated Deployment and Configuration Engines. Ansible
PPTX
Sergey Dzyuban "To Build My Own Cloud with Blackjack…"
PDF
Deployment automation framework with selenium
PPTX
7 steps to simplifying your AI workflows
PDF
OSDC 2013 | Introduction into Chef by Andy Hawkins
KEY
DjangoCon 2010 Scaling Disqus
Ansible: How to Get More Sleep and Require Less Coffee
Moving Windows Applications to the Cloud
Getting to Walk with DevOps
Ansible presentation
ansible-app-platforme-2024-presentation-
Ansible benelux meetup - Amsterdam 27-5-2015
Power of Azure Devops
Continuous Delivery: How RightScale Releases Weekly
PyCon India 2012: Celery Talk
Stress Free Deployment - Confoo 2011
Auto Deploy Deep Dive – vBrownBag Style
Training Slides: 103 - Basics - Simple Tungsten Clustering Installation
NSBCon UK nservicebus on Azure by Yves Goeleven
OpenStack Deployments with Chef
Automated Deployment and Configuration Engines. Ansible
Sergey Dzyuban "To Build My Own Cloud with Blackjack…"
Deployment automation framework with selenium
7 steps to simplifying your AI workflows
OSDC 2013 | Introduction into Chef by Andy Hawkins
DjangoCon 2010 Scaling Disqus
Ad

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PPTX
A Presentation on Artificial Intelligence
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Modernizing your data center with Dell and AMD
A Presentation on Artificial Intelligence
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Monthly Chronicles - July 2025
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm

Hosting Ruby Web Apps