Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

incident.io 10 min read Incident mediumAdept

Battling database performance

Intermittent API timeouts at incident.io over two weeks traced back to requests blocking on Go's database/sql client-side connection pool, with no single slow query or pool to blame. The team shipped 24 changes along the way. These included materialised views, new indexes, query rewrites, a one-second lock timeout on transactions, and moving Slack webhook handling onto PubSub. They also built per-operation tracking of connection-hold time using an ngrok/sqlmw middleware and context counters that avoid double-counting inside transactions. The root cause turned out to be an unnecessary transaction wrapped around every Slack modal submission. Many short transactions added together had exhausted the pools, and removing it ended the timeouts.

Related posts

  • How to Handle Database Connection Pooling

    Railway mediumAdept

    Connection pooling keeps a set of reusable database connections open, so requests check one out and return it instead of opening and closing a connection per query. A walkthrough builds a Node.js Express app with node-postgres, comparing per-query Client connections against a Pool (max 20, connection and idle timeouts) over 100 concurrent queries. Query latency is measured with prom-client histograms. In this local setup the pooled queries finished roughly 3x faster in total, and more individual queries completed within the low-millisecond buckets.

  • Using Neon’s Scale to Zero with Long-Running Applications

    Neon mediumAdept

    Neon's scale to zero suspends a Postgres compute after an idle window (only when no WAL senders are active and autovacuum isn't running), which severs connections held by long-running servers. A naive node-postgres Client crashes on the resulting unhandled error event. A client-side pg.Pool with an error handler tolerates the dropped connections and reconnects on demand, waking the database. In Apache Bench tests the pool beat per-request connections by more than 10x (about 46ms vs 678ms average latency, 370 vs 26 req/s), with the same pattern shown in a Fastify, Drizzle and HTMX example app.

  • Incident Report: April 23rd, 2025

    Railway mediumAdept

    A Google Cloud SQL maintenance window took Railway's networking control plane Postgres read replica offline for about 10 minutes, destabilizing edge, private networking and TCP proxy traffic across all regions, worst in Asia. Control plane instances crashed on database connection errors because of improper error handling, and each restart evicted the in-memory routing cache, which could not be refetched while Postgres was down. Slow cache warming delayed recovery until 09:28 UTC. Planned fixes include regional control planes to limit blast radius, graceful handling of DB errors, a persistent routing cache as a fallback, faster startup, and Cloud SQL maintenance settings that keep primary and replica from being maintained at the same time.

  • Delayed Start Compute Operations – Triggering Event

    Neon mediumAdept

    Neon's 2025-05-16 us-east-1 outage was triggered when the Postgres planner for the control plane database switched to a suboptimal index for the Activity Monitor query that finds idle Computes to suspend. The resulting broad scan of the tens-of-millions-row computes table saturated CPU and pushed fetchEndpointWithCompute latency from hundreds of milliseconds to over 100 seconds. With suspensions stalled, running VMs grew past the planned 6,000 and IP allocation failed. Neon fixed it by running ANALYZE and wrapping the expensive subquery in a materialized CTE as an optimization fence. Planned follow-ups include more aggressive garbage collection to shrink the table and moving historical data to an OLAP system.

  • Intermittent downtime from repeated crashes

    incident.io mediumAdept

    A poison-pill Pub/Sub message crashed incident.io's Go monolith on Heroku repeatedly, causing 13 minutes of downtime over 32 minutes. The root cause was an unhandled panic inside goroutines spawned by the Google Cloud Pub/Sub client's Receive method, which a parent goroutine's recover() cannot catch. Debugging was slowed because Go's full goroutine stack dumps overwhelmed Heroku's log rate limits, and the abrupt exit also killed Sentry reporting. The team recovered by purging suspect subscriptions, then added a recover inside the message handler and split web, worker and cron work into separate Heroku dyno tiers so worker crashes can't take down request serving.

The quest for software engineering knowledge.

Look:
Layout: