Deep-dive on the Next Gen Platform. Join the Webinar!

Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Visit the Heroku Blog

    Find news and updates from Heroku in the blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Working with Node.js
      • Troubleshooting Node.js Apps
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Working with AI
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Patterns & Best Practices
  • Optimizing Resource Costs

Optimizing Resource Costs

English — 日本語に切り替える

Last updated October 11, 2024

Table of Contents

  • Optimizing for Prototypes or Heroku Buttons
  • Optimizing for Review Apps and CI Apps
  • Optimizing for Staging Apps
  • Optimizing for Production Apps
  • How to Track Your Usage and Costs

Heroku prorates all costs to the second for the resources that you use. This article provides guidance on how to optimize Heroku resources and minimize costs for different use cases.

Optimizing for Prototypes or Heroku Buttons

Use the least expensive plans available to you when you’re building prototypes and experimenting with your app. For example, Eco dynos sleep after 30 minutes of inactivity and don’t consume hours while sleeping.

Only personal apps can use Eco dynos. Personal apps are apps that aren’t a part of a Heroku Team or Enterprise Team.

If you have apps that rely on app.json to deploy, such as apps deployed through Heroku Buttons or set up with the Platform API, specify the appropriate plan within the app.json. Heroku Buttons already default to the least expensive plans.

{
  "formation": {
    "web": {
      "quantity": 1,
      "size": "basic"
    }
  }
}

When you’re done experimenting with your prototype, make sure you:

  • Scale down your dynos so they don’t stay running
  • Remove or delete any database resources that are no longer in use. You can export Heroku Postgres data that you want to keep.
  • Downgrade or delete any third-party add-ons from your app

Optimizing for Review Apps and CI Apps

Review Apps default to using the least expensive dyno available to you. You can optimize costs for your Review Apps by:

  • Setting Review Apps to be destroyed automatically after 1, 2, 5, 14, or 30 days of inactivity
  • Manually deleting any Review Apps as soon as you’re done testing
  • Using In-Dyno databases for Heroku Postgres and Heroku Key-Value Store for Heroku CI. In-Dyno databases run inside your test-run’s dynos and are ephemeral, so they provide great flexibility and speed for test runs in your CI workflow.
  • Specifying low-cost plans for add-ons in the app.json. If your Review Apps or CI appears to ignore your app.json file, contact Heroku Support.

Optimizing for Staging Apps

Staging apps are used to test changes in a production-like setting before promoting to production. It’s important to adjust the resources while testing so you’re not using more than necessary.

Upgrade to larger resource plans as necessary when you’re:

  • Testing major code changes
  • Executing database migrations

Staging apps incur costs for resources used. Optimize the resources in your staging apps by:

  • Load testing to see how it performs under real-world traffic. Use these results to help determine appropriate scaling on your production apps.
  • Scaling down the dynos when you’re done testing
  • Using a third-party add-on from the Elements marketplace to put the dynos to sleep when they’re inactive
  • Using Heroku Scheduler to run one-off dynos at scheduled intervals. Dynos are automatically turned off after the task is completed.

Optimizing for Production Apps

Optimizing Dynos

Consider optimizing your dyno usage so your app makes the most efficient use of available resources. Depending on factors like how much CPU or memory your app uses, different dyno types are better suited.

It’s a good idea to monitor your apps and databases to optimize your usage. Adding an application performance monitoring (APM) add-on, such as New Relic or Librato can monitor your resource usage and collect metrics over time.

Scale down your dynos when they’re not needed by:

  • Manually scaling your app’s dynos through the Heroku Dashboard or the CLI
  • Enabling autoscaling on Performance, Private and Shield dynos after optimizing dyno performance
  • Using a third-party add-on from the Elements marketplace

Optimizing Heroku Postgres

Choose the right Heroku Postgres plan depending on your app’s usage and requirements for availability and uptime. The right plan depends on how much downtime your app can tolerate on a monthly basis. You can also consider using Terraform to create and remove your apps on demand without wasting resources.

You can further improve the performance of your Heroku Postgres database by knowing your specific workload and doing performance tuning. You can also consider enabling WAL compression. Keep in mind, enabling this feature reduces Write-ahead Logging (WAL) volume at the cost of a slight increase in CPU usage.

Steps to optimize the performance of your database include:

  • Tracking system metrics on your application’s logs
  • Controlling the number of connections to your database and using connection pooling when appropriate to avoid connection limits and Out of Memory errors.
  • Identifying under-optimized queries
  • Watching out for locks in the database
  • Cleaning up dead rows in the database periodically
  • Considering separate caching
  • Running the heroku pg:diagnose command to find common issues

You can learn more in Heroku Postgres Database Tuning.

How to Track Your Usage and Costs

  • For non-Heroku Enterprise accounts, track your current usage and costs on your account’s Billing tab.
  • For Enterprise accounts, track your current usage and costs on the Usage tab on your Enterprise Team page.

Keep reading

  • Patterns & Best Practices

Feedback

Log in to submit feedback.

Writing Best Practices For Application Logs PgBouncer Configuration

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices