---
title: "Battling database performance"
description: "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."
url: "https://swe.quest/articles/battling-database-performance-5c5eb431f69f9020"
canonical: "https://incident.io/blog/database-performance"
source: "incident.io"
published: "2023-04-20"
difficulty: "medium"
kind: "Incident"
reading_minutes: 10
tags: ["postgres","performance","observability","go","incident-response"]
---

# Battling database performance

A post on [incident.io](https://swe.quest/sources/incident-io.md), published 2023-04-20, 10 min read, Incident. Original: [https://incident.io/blog/database-performance](https://incident.io/blog/database-performance)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Go](https://swe.quest/tags/go.md) (Languages)
- [Incidents & postmortems](https://swe.quest/tags/incident-response.md) (Reliability & operations)

## Prerequisites

- Go database/sql ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))
- database connection pooling ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- SQL transactions ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- distributed tracing ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))

## Keywords

database/sql, ngrok/sqlmw, gorm, PubSub, Heroku Postgres, Grafana, Slack

## Related posts

- [How to Handle Database Connection Pooling](https://swe.quest/articles/how-to-handle-database-connection-pooling-1d65f2947c3645f4.md): Railway · 2024-12-13 · Medium · 13 min read · PostgreSQL, JavaScript, Performance engineering, Databases
  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.
- [Using Neon’s Scale to Zero with Long-Running Applications](https://swe.quest/articles/using-neon-s-scale-to-zero-with-long-running-applications-bbe64dd8466d86d8.md): Neon · 2024-01-24 · Medium · 7 min read · PostgreSQL, Serverless, Resilience, JavaScript, Performance engineering
  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.
- [Incident Report: April 23rd, 2025](https://swe.quest/articles/incident-report-april-23rd-2025-f0e6e4113e1badba.md): Railway · 2025-04-23 · Medium · 4 min read · Incidents & postmortems, Resilience, PostgreSQL, Networking, Caching
  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.
- [Delayed Start Compute Operations – Triggering Event](https://swe.quest/articles/delayed-start-compute-operations-triggering-event-db99144a3f6489a4.md): Neon · 2025-05-30 · Medium · 4 min read · PostgreSQL, Incidents & postmortems, Query engines, Serverless, Performance engineering
  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.
- [Intermittent downtime from repeated crashes](https://swe.quest/articles/intermittent-downtime-from-repeated-crashes-9e00050b528fb037.md): incident.io · 2022-11-30 · Medium · 11 min read · Incidents & postmortems, Go, Resilience, Queues & messaging
  A poison-pill Pub/Sub message crashed incident.io's Go monolith on Heroku repeatedly, causing 13 minutes of downtime over 32 minutes.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
