Cold Starts with Apollo + Strapi + Heroku + Netlify

System Information
  • Strapi Version: 3.2.5
  • Operating System: Heroku
  • Database: postgres
  • Node Version: Heroku defaults?
  • NPM Version: Heroku defaults?
  • Yarn Version: Heroku defaults?

I have an app that uses Strapi & GraphQL, with the strapi app deployed on Heroku and a NextJS front end deployed on Netlify.

In production, I am getting pretty lengthy cold starts when loading the apollo queries on the homepage. Once the app is running the queries run super fast. In dev, everything works great.

I just switched the frontend to use rest endpoints instead of the graphQl queries, and the cold starts are basically gone now, so seems to be something Apollo related? Or maybe a Heroku thing?

Any recommendation on how to optimize these queries to eliminate the cold start? Or tooling to even see where the bottleneck is?


    "knex": "<0.20.0",
    "pg": "^8.3.3",
    "sqlite3": "latest",
    "strapi": "^3.2.5",
    "strapi-admin": "^3.2.5",
    "strapi-connector-bookshelf": "^3.2.5",
    "strapi-plugin-content-manager": "^3.2.5",
    "strapi-plugin-content-type-builder": "^3.2.5",
    "strapi-plugin-email": "^3.2.5",
    "strapi-plugin-graphql": "^3.2.5",
    "strapi-plugin-upload": "^3.2.5",
    "strapi-plugin-users-permissions": "^3.2.5",
    "strapi-provider-upload-cloudinary": "^3.2.5",
    "strapi-utils": "^3.2.5"

and the config/env/production

module.exports = ({ env }) => ({
  defaultConnection: "default",
  connections: {
    default: {
      connector: "bookshelf",
      settings: {
        client: "postgres",
        host: env("DATABASE_HOST"),
        database: env("DATABASE_NAME"),
        username: env("DATABASE_USERNAME"),
        password: env("DATABASE_PASSWORD"),
        schema: "public",
        ssl: { rejectUnauthorized: false }
      options: {}

That would be a Heroku thing and how they sleep the dynos, but it depends on the plan you are using.

This is based on the engine object in your package.json (excluding yarn which heroku doesn’t use iirc)

awesome. thanks for the feedback.

1 Like

Do let me know if you still see some weird errors :slight_smile: