Back to Blog
Engineering

How We Scaled Our PostgreSQL Database to Handle 10M Rows

Engineering Team
March 15, 2024
How We Scaled Our PostgreSQL Database to Handle 10M Rows

The Initial Problem

When one of our clients experienced viral growth, their primary dashboard load times degraded from 200ms to 5 seconds. The bottleneck was a PostgreSQL database performing full table scans on a rapidly expanding events table.

The Solutions Implemented

  1. Index Optimization: We identified missing composite indexes on frequently filtered columns.
  2. Materialized Views: For complex analytical queries that didn't require real-time accuracy, we implemented materialized views refreshed on a schedule.
  3. Connection Pooling: We introduced PgBouncer to manage the growing number of simultaneous connections from the serverless edge functions.

The result was a return to 150ms load times and a highly stable infrastructure.