Scaling PgBouncer Beyond a Single CPU Core
ClickHouse Cloud's managed Postgres service uses a custom PgBouncer sharding approach to overcome single-CPU-core bottlenecks, enabling the connection pooler to scale horizontally across multiple cores for higher throughput and reduced latency.
Background
PgBouncer is a widely used, lightweight connection pooler for PostgreSQL that typically runs on a single CPU core. This article, from ClickHouse (a separate, open-source column-oriented database known for real-time analytics, not to be confused with ClickHouse the company offering a managed PostgreSQL service called ClickHouse Cloud), describes a production problem: when thousands of client connections share one PgBouncer process, it becomes CPU-bound and becomes a bottleneck, limiting throughput. The post walks through how the engineering team profiled the bottleneck, diagnosed the cause (internal connection bookkeeping and locks in PgBouncer's event loop), and implemented a practical workaround—running multiple PgBouncer instances behind a load balancer—rather than modifying PgBouncer itself. It's a real-world case study in diagnosing and scaling a bottleneck in database infrastructure.