Supabase Blog

Supavisor: Scaling Postgres to 1 Million Connections

thumbnail

Supavisor: Scaling Postgres to 1 Million Connections

  • Supavisor is a Postgres connection pooler that can handle millions of connections.
  • To simulate 1,000,000 concurrent connections, 20 AWS EC2 instances with 16 cores and 32GB of RAM were used.
  • Supavisor achieved 250,000 concurrent connections with a pool of 400 direct connections to the database.
  • The system processed 20,000 queries per second (QPS), but the database became the bottleneck at this point.
  • Horizontal scalability was examined by deploying two 64-core Supavisor instances, one connected directly to the database and the other relaying queries through the first.
  • The directly connected instance handled the same load as when handling 500,000 concurrent clients in a single-node mode.
  • Scalability can be further enhanced by adding more databases or read-replicas to increase QPS or deploying additional Supavisor instances to accommodate tens of millions of connections.
  • Supavisor was compared to pgbouncer on Supabase Platform, and it will be added to the self-hosted stack after testing across the database fleet.

Impact on Query Duration

  • Query duration was measured after scaling up to 20,000 QPS.
  • The median query duration was 18.4ms, p95 was 46.9ms, and p99 was 68ms.
  • Higher load and concurrent queries led to increased execution times on the database side.

Supavisor on Supabase Platform

  • Supabase Platform currently uses pgbouncer as a connection pooler, running on the same instance as the database.
  • Supavisor was tested on Supabase Platform and query durations were compared.
  • Supavisor will be added to the self-hosted stack after testing across the database fleet.

Conclusion

  • Supavisor is a scalable Postgres connection pooler that can handle millions of connections.
  • It has been tested with 250,000 concurrent connections and a pool of 400 direct connections to the database.
  • Horizontal scalability can be achieved by deploying multiple Supavisor instances and adding more databases or read-replicas.
  • Supavisor has been compared to pgbouncer on Supabase Platform and will be added to the self-hosted stack after testing.
  • The impact on query duration was measured, with a median of 18.4ms, p95 of 46.9ms, and p99 of 68ms at 20,000 QPS.