Categories
Cloud Deployment Heroku Ruby

Deploying Ruby Apps to Heroku: Git Push to Production

Introduction

Deploying web applications used to be painful. Set up a server, configure Apache, install dependencies, manage databases, worry about scaling. It was complex and time-consuming.

Heroku changes this. It's a cloud platform that runs your Ruby applications with minimal configuration. Deploy with git push. Scale with a slider. Focus on code, not infrastructure.

I've been using Heroku for several months, and it's transformed how I deploy applications. Let me show you how it works.

What is Heroku?

Heroku is a Platform as a Service (PaaS) for Ruby applications. You push code via Git, and Heroku handles:

  • Server configuration
  • Dependency installation
  • Process management
  • Scaling
  • Load balancing
  • Monitoring

You write code. Heroku runs it.

Pricing:

  • Free tier for small apps
  • $0.05/hour per dyno (process) for scaling
  • Add-ons (databases, caching, etc.) cost extra

Perfect for side projects, prototypes, and production apps.

Getting Started

1. Sign up: Create account at heroku.com

2. Install Heroku gem:

gem install heroku

3. Authenticate:

heroku keys:add

This uploads your SSH public key.

Preparing Your App

Heroku requires a few things:

1. Git repository:

git init
git add .
git commit -m "Initial commit"

2. Gemfile:

Rails 3 includes this. For other apps:

source 'http://rubygems.org'

gem 'sinatra'
gem 'thin'

3. Specify Ruby version (in .gems file):

sinatra
thin

That's it. No server configuration files, no deployment scripts.

Deploying

Create Heroku app:

heroku create myapp

This creates a new app and adds a Git remote.

Deploy:

git push heroku master

Heroku receives your code, detects it's a Ruby app, installs gems, and starts your application.

Visit your app:

heroku open

You're live. That's it.

Database Setup

Heroku provides PostgreSQL by default.

Run migrations:

heroku rake db:migrate

Seed data:

heroku rake db:seed

Database console:

heroku db:console

Everything you do locally works on Heroku.

Configuration

Set environment variables:

heroku config:add S3_KEY=xxx S3_SECRET=yyy

Access in your app:

S3_KEY = ENV['S3_KEY']

Never commit secrets to Git. Use config vars.

View config:

heroku config

Viewing Logs

Real-time logs:

heroku logs --tail

Last 100 lines:

heroku logs

Logs help debug production issues.

Running Commands

Run rake tasks:

heroku rake db:migrate
heroku rake some:task

Rails console:

heroku console

Any command:

heroku run ruby script.rb

Scaling

Heroku runs your app on "dynos" (lightweight containers).

Check current state:

heroku ps

Scale web processes:

heroku scale web=2

Now you have 2 web processes handling requests.

Add worker processes:

heroku scale worker=1

For background jobs using Delayed Job or Resque.

Scaling is instant. No server configuration needed.

Add-ons

Heroku has an add-on ecosystem:

Caching (Memcache):

heroku addons:add memcache:5mb

MongoDB:

heroku addons:add mongohq:free

Email (SendGrid):

heroku addons:add sendgrid:free

Monitoring (New Relic):

heroku addons:add newrelic:bronze

Add-ons integrate automatically. Configuration is automatic.

Custom Domains

Use your own domain:

heroku addons:add custom_domains
heroku domains:add www.example.com

Update DNS:

www.example.com CNAME proxy.heroku.com

SSL is available as an add-on.

Deployment Workflow

My typical workflow:

1. Develop locally:

rails server

2. Commit changes:

git add .
git commit -m "Add feature"

3. Deploy:

git push heroku master

4. Run migrations if needed:

heroku rake db:migrate

5. Verify:

heroku open
heroku logs --tail

From commit to production in seconds.

Database Backups

Free tier doesn't include backups. For production:

heroku addons:add pgbackups:basic

Manual backup:

heroku pgbackups:capture

Download backup:

heroku pgbackups:url

Essential for production apps.

Example: Deploying a Sinatra App

app.rb:

require 'sinatra'

get '/' do
  'Hello Heroku!'
end

get '/about' do
  'About page'
end

config.ru:

require './app'
run Sinatra::Application

Gemfile:

source 'http://rubygems.org'
gem 'sinatra'
gem 'thin'

Deploy:

git init
git add .
git commit -m "Initial commit"
heroku create
git push heroku master
heroku open

A working Sinatra app in under a minute.

Rails 3 Specifics

Rails 3 apps work out of the box.

Gemfile must include:

gem 'pg'  # PostgreSQL

Remove sqlite3 from Gemfile (Heroku uses PostgreSQL).

Asset pipeline (Rails 3.1 when it launches):

Heroku will precompile assets automatically.

Troubleshooting

App won't start:

Check logs:

heroku logs

Common issues:

  • Missing gems in Gemfile
  • Database not migrated
  • Wrong Ruby version

Slow performance:

Check dyno count:

heroku ps

Scale up:

heroku scale web=2

Database issues:

Reset database (destroys data):

heroku pg:reset DATABASE_URL
heroku rake db:migrate

Limitations

Heroku isn't perfect:

Ephemeral filesystem: Don't store uploads on disk. Use S3.

PostgreSQL only: MySQL requires workarounds

Cost: Free tier is generous, but scaling gets expensive

No root access: Can't install arbitrary software

Platform lock-in: Moving off Heroku takes work

For most apps, these aren't dealbreakers.

Alternatives

Other PaaS options:

Engine Yard: More control, more complex

Google App Engine: Different approach, Python/Java

Amazon Elastic Beanstalk: Just launched, similar to Heroku

Your own server: Maximum control, maximum work

Heroku's simplicity is hard to beat.

Best Practices

Use config vars for secrets: Never commit API keys

Enable backups: For production apps

Monitor performance: Use New Relic or similar

Keep Gemfile.lock in Git: Ensures consistent dependencies

Test before deploying: Run tests locally first

Use branches:

git push heroku mybranch:master

Cost Estimation

Free tier:

  • 1 web dyno
  • 5MB PostgreSQL database
  • Good for hobby projects

Small production app:

  • 2 web dynos: $72/month
  • 20GB database: $15/month
  • SendGrid email: Free
  • Total: ~$87/month

Medium app:

  • 4 web dynos: $144/month
  • Larger database: $50/month
  • Caching: $25/month
  • Total: ~$219/month

Much cheaper than managing your own servers.

Real-World Example

I run a project management app on Heroku:

Configuration:

  • 3 web dynos
  • 1 worker dyno
  • PostgreSQL (20GB)
  • Memcache (100MB)
  • SendGrid for email
  • New Relic monitoring

Cost: ~$140/month

Benefits:

  • Zero server management
  • Instant scaling
  • Automated backups
  • Great uptime

Worth every penny.

Developer Experience

What I love about Heroku:

Deployment is trivial: git push and done

Scaling is easy: Slider in web interface or single command

Add-ons are seamless: One command to add functionality

Documentation is excellent: Clear, comprehensive guides

Focus on code: Not infrastructure

Moving Forward

Start with Heroku's free tier. Deploy a simple app. Experience the workflow.

As your app grows, scale up. Add dynos, upgrade database, enable add-ons.

Heroku grows with you from prototype to production.

The platform keeps improving. New add-ons appear regularly. Performance gets better. The ecosystem expands.

For Ruby developers, Heroku is the easiest path from code to production. The friction of deployment disappears. You focus on building great applications.

Try Heroku for your next project. Deploy something today. Experience what modern deployment should feel like.

Git push to production. It's that simple.

By Shishir Sharma

Shishir Sharma is a Software Engineering Leader, husband, and father based in Ottawa, Canada. A hacker and biker at heart, and has built a career as a visionary mentor and relentless problem solver.

With a leadership pedigree that includes LinkedIn, Shopify, and Zoom, Shishir excels at scaling high-impact teams and systems. He possesses a native-level mastery of JavaScript, Ruby, Python, PHP, and C/C++, moving seamlessly between modern web stacks and low-level architecture.

A dedicated member of the tech community, he serves as a moderator at LUG-Jaipur. When he’s not leading engineering teams or exploring new technologies, you’ll find him on the open road on his bike, catching an action movie, or immersed in high-stakes FPS games.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.