All topics
Cloud · Learning hub

Heroku notes for developers

Master Heroku with a curated set of 2 developer notes — core concepts, patterns, and interview prep. Maintained by the DevRecall team.

Save this stack to your DevRecallMore Cloud notes
Heroku

Deployment, Dynos & Config

Heroku: Deployment, Dynos & Config Heroku is a PaaS (Platform as a Service) that runs apps in containers called dynos. Deploy via Git push, Docker, or CI/CD. He

Heroku: Deployment, Dynos & Config

Heroku is a PaaS (Platform as a Service) that runs apps in containers called dynos. Deploy via Git push, Docker, or CI/CD. Heroku handles OS, runtime, scaling, and infrastructure.

Deploy via Git

# Install Heroku CLI
brew tap heroku/brew && brew install heroku

# Login and create app
heroku login
heroku create my-app-name
# or: heroku create  (auto-generates a name)

# Deploy
git push heroku main

# View logs
heroku logs --tail

# Open app in browser
heroku open

# Run one-off commands
heroku run bash
heroku run npx prisma migrate deploy
heroku run python manage.py migrate

Procfile

The Procfile defines process types. Heroku reads it to know how to start your app.

# Procfile — no file extension, at repo root

# Web process (receives HTTP traffic)
web: node dist/server.js
# or:
web: npm start
# or:
web: gunicorn myapp.wsgi

# Background worker
worker: node workers/queue-processor.js

# Release phase — runs before new dynos start (use for migrations)
release: npx prisma migrate deploy
# or:
release: python manage.py migrate

Dynos

  • Eco/Basic ($5-7/mo): single dyno, sleeps after 30 min of inactivity — for hobby projects

  • Standard-1X/2X ($25-50/mo): always-on, 512MB-1GB RAM

  • Performance-M/L ($250-500/mo): dedicated compute, auto-scaling available

  • Free tier: discontinued in 2022 — use Railway, Render, or Fly.io for free alternatives

  • Dyno count: heroku ps:scale web=2 — run 2 web dynos for load distribution

  • Dyno formation: heroku ps — see running dynos and their status

# Scale dynos
heroku ps:scale web=2 worker=1

# Check dyno status
heroku ps

# Restart dynos
heroku restart
heroku dyno:restart web.1   # restart specific dyno

Config Vars (Environment Variables)

# Set config vars
heroku config:set DATABASE_URL=postgres://...
heroku config:set NODE_ENV=production REDIS_URL=redis://...

# View all config vars
heroku config

# Get one value
heroku config:get DATABASE_URL

# Remove a var
heroku config:unset MY_VAR

# Copy config from one app to another
heroku config -s --app source-app | xargs heroku config:set --app target-app

Buildpacks

# Heroku auto-detects language via buildpacks
# Node.js: package.json present
# Python: requirements.txt or Pipfile
# Ruby: Gemfile

# Specify explicitly
heroku buildpacks:set heroku/nodejs
heroku buildpacks:set heroku/python

# Multiple buildpacks (e.g., Node + Python)
heroku buildpacks:add --index 1 heroku/nodejs
heroku buildpacks:add --index 2 heroku/python

# Custom buildpack
heroku buildpacks:set https://github.com/owner/buildpack.git
Heroku

Add-ons, Pipelines & Production Tips

Heroku: Add-ons, Pipelines & Production Tips Add-ons Add-ons are third-party services provisioned and billed through Heroku. They automatically set config vars

Heroku: Add-ons, Pipelines & Production Tips

Add-ons

Add-ons are third-party services provisioned and billed through Heroku. They automatically set config vars in your app.

# Common add-ons
heroku addons:create heroku-postgresql:essential-0   # PostgreSQL
heroku addons:create heroku-redis:mini               # Redis
heroku addons:create papertrail:choklad              # Log management
heroku addons:create sendgrid:starter                # Email
heroku addons:create scheduler:standard              # Cron jobs
heroku addons:create newrelic:wayne                  # APM monitoring

# List installed add-ons
heroku addons

# Open add-on dashboard
heroku addons:open heroku-postgresql

Heroku Scheduler

  • Add-on for running jobs on a schedule (like cron) — free tier available

  • Intervals: every 10 minutes, every hour, every day at a specific UTC time

  • Configure via: heroku addons:open scheduler

  • Each job runs in a one-off dyno — charged for dyno time

  • Not reliable for precise timing — may run ±1 minute from scheduled time

  • For precise cron, use a worker dyno with node-cron or APScheduler (Python)

Review Apps & Pipelines

Heroku Pipelines provide staging environments and automated review apps for pull requests.

# Pipeline stages: development → staging → production
heroku pipelines:create my-pipeline --app my-app-staging --stage staging

# Promote from staging to production (no rebuild — same slug)
heroku pipelines:promote --app my-app-staging

# Review Apps: auto-created per PR (configure in Dashboard → Review Apps)
# - Spun up when PR opens, destroyed when PR closes
# - Shares config from staging (with overrides in app.json)

# app.json — configures review apps
cat app.json
{
  "name": "My App",
  "description": "Review app config",
  "env": {
    "NODE_ENV": { "value": "staging" },
    "FEATURE_FLAGS": { "value": "all" }
  },
  "formation": {
    "web": { "quantity": 1, "size": "standard-1x" }
  },
  "scripts": {
    "postdeploy": "npx prisma migrate deploy && node scripts/seed.js"
  },
  "addons": ["heroku-postgresql:essential-0"]
}

Production Best Practices

  • Use release phase for migrations: release: npx prisma migrate deploy — ensures migration runs before traffic shifts

  • Health check endpoint: Heroku checks / by default; return 200 quickly or configure in Dashboard

  • Preboot: enable in Settings → enable preboot — starts new dynos before killing old ones (zero-downtime deploy)

  • Log drains: stream logs to Datadog, Papertrail, Loggly — heroku logs only keeps 1500 lines

  • SSL: automatically provisioned for *.herokuapp.com and custom domains (ACM)

  • Metrics: Dashboard → Metrics shows response time, throughput, memory, errors per dyno

  • Memory limits: if dyno exceeds RAM limit, it's "swapped" → R14 error → R15 = killed. Monitor with heroku ps

Alternatives Worth Knowing

  • Railway: closest Heroku replacement, Postgres included, generous free tier, similar DX

  • Render: free tier with auto-sleep, good for hobby projects, native Docker support

  • Fly.io: more control, runs Docker containers globally, good for latency-sensitive apps

  • Vercel / Netlify: better for Next.js/frontend — serverless functions, not persistent servers

  • AWS Elastic Beanstalk: Heroku-like PaaS on AWS infrastructure, more configuration needed

Keep your Heroku knowledge sharp.

Save this stack to your personal DevRecall — add your own notes, track what you're learning, and share what you know with the community.

Get started — free forever