flaibo
Code Technical

Debugging Help

Help me debug: my Next.js API route is returning 500 errors intermittently in production but never in dev

No card required

What this brief specifies

The stack

Next.js 15 on Vercel, talking to Postgres via Supabase, using the Supabase client with a service role key.

When it started

Right after traffic jumped from roughly 1,000 requests a day to roughly 15,000 in the space of a week.

What's actually failing

About 3% of requests return 500, with 'Error: Connection terminated unexpectedly' from the Postgres driver.

What makes this hard

What makes this one hard is that every troubleshooting step so far was done correctly and still turned up nothing: the service role key is valid, the query works in isolation, redeploying didn't help, and 20 minutes of watching logs found nothing, because a 3% failure rate might not throw a single error in that window. The one fact that actually points somewhere is timing, not symptom: this started right after traffic went from roughly 1,000 requests a day to roughly 15,000, a jump big enough to change how many concurrent serverless function instances open connections to the same Postgres database at once, something a query run once, by hand, would never reveal. A generic 500-error checklist says check credentials and restart the deployment, both already done; it doesn't point at the mismatch between a request volume up 15x and a connection pattern never tested at that scale.

FounderConsultantSmeCorporateStudent

Frequently asked questions

Carrying forward the actual stack, exactly when this started, and the specific failure signature means the debugging an AI assistant helps with starts from the connection-pattern question instead of re-checking credentials and redeploying again. The next intermittent production-only bug that shows up right after a real traffic jump gets investigated against that same timeline instead of a generic error-message search.

Ready to try this in Flaibo?

Get started free

Your context everywhere