Strapi v4 + Postgres + Render.com = Error "Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?"

Actually, I might have been wrong. Strapi v4.2.3 deploys on Railway.app easily, but it still has HUGE performance issues.

I use Strapi as the backend for a Next.js app.

V3 on Render worked quite well and static page generation on Next.js never had a problem.
V4 on Render just fails. I’m currently dealing with Render support, but basically their answer is: “A lot of people have this problem, Strapi is extremely resource hungry, not much we can do when your app crashed because it runs out of memory.”

I can deploy v4 on Railway.app, and run the backend just fine. (see my post above).

BUT…

When deploying the Next.js frontend on Vercel, any static page generation crashes Strapi (on Railway.app) when Next.js collects the page data from getStaticProps().

The requests for pretty much any api endpoint with population of fields creates a huge spike in memory use and the requests time out, or often the server crashes.

I changed all the getStaticProps calls in the Next.js frontend to getServerSideProps effectively disabling static page generation and instead using SSR to load one page at a time (and cache it).

Only one call I need to do on build. I’m generating an RSS feed for a podcast. To generate that I need to do ONE API call to an endpoint containing just 8 items in the collection with ONE dynamic zone that needs to be populated.

Running that single query spikes memory use to over 1GB and effectively halts execution of the request on Railway.com.

I found that population depth had a huge impact on performance. It feels like it loads the whole collection of possibly linked relations into memory first, only to select the the one that was actually linked for that record. That’s just a feeling, I could verify that. It’s like it gets stuck in some sort of infinite loop once population goes deeper than a level or so.

To fix it, I now select as few fields/relations as possible, which helps. but still trying to figure out how to specify which components of a dynamic zone to populate. (But that’s another story).

Hope that helps someone, until Strapi gets a bit more performant.