---
title: "PGKeeper: Building the bouncer we needed for Postgres"
description: "Figma replaced PgBouncer with PGKeeper, a Go service built on PGX that sits between its DBProxy router and each Postgres instance."
url: "https://swe.quest/articles/pgkeeper-building-the-bouncer-we-needed-for-postgres-b0a410376e101175"
canonical: "https://www.figma.com/blog/pgkeeper-building-the-bouncer-we-needed-for-postgres/"
source: "Figma"
published: "2026-05-04"
difficulty: "medium"
kind: "Case study"
reading_minutes: 19
tags: ["postgres","resilience","go","databases","scalability"]
---

# PGKeeper: Building the bouncer we needed for Postgres

A post on [Figma](https://swe.quest/sources/figma.md), published 2026-05-04, 19 min read, Case study. Original: [https://www.figma.com/blog/pgkeeper-building-the-bouncer-we-needed-for-postgres/](https://www.figma.com/blog/pgkeeper-building-the-bouncer-we-needed-for-postgres/)

## Summary

Figma replaced PgBouncer with PGKeeper, a Go service built on PGX that sits between its DBProxy router and each Postgres instance. Clients reach it over gRPC with per-query metadata such as traffic tier and request source. PgBouncer was ruled out for its single-threaded scaling ceiling, lack of prioritization and backpressure, and weak protection against connection churn. Pooling inside DBProxy was ruled out because hundreds of replicas cannot share a ~100-connection pool, and PGCat would have required a fork. PGKeeper token-bucket rate-limits both connection creation and teardown, warms pools before taking traffic, and avoids churn with bounded result draining, automatic ROLLBACK, and context cancellation via pg\_cancel\_backend plus SELECT 1. Its priority-based semaphore admission control uses CoDel to shed stale lower-priority work during concurrency spikes.

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)
- [Resilience](https://swe.quest/tags/resilience.md) (Distributed systems)
- [Go](https://swe.quest/tags/go.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [Scaling](https://swe.quest/tags/scalability.md) (Distributed systems)

## Prerequisites

- PostgreSQL connection model ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- connection pooling
- load shedding basics ([easy posts on Resilience](https://swe.quest/tags/resilience.md?difficulty=easy))
- gRPC ([easy posts on RPC & gRPC](https://swe.quest/tags/rpc.md?difficulty=easy))

## Keywords

PGKeeper, PgBouncer, PGCat, PGX, CoDel, DBProxy, bradenaw/backpressure, gRPC

## Related posts

- [Why we built yet another Postgres connection pooler](https://swe.quest/articles/why-we-built-yet-another-postgres-connection-pooler-daf218b5177e95f8.md): PgDog · 2026-07-06 · Medium · 4 min read · PostgreSQL, Rust, Concurrency, Databases
  PgDog is a Rust Postgres proxy whose connection pooler avoids the leaky abstractions of PgBouncer and RDS Proxy.
- [PgBouncer is now available in Supabase](https://swe.quest/articles/pgbouncer-is-now-available-in-supabase-7611d240679e4c4c.md): Supabase · 2021-04-02 · Medium · 4 min read · PostgreSQL, Serverless, Scaling
  Supabase now bundles PgBouncer, co-located on the same server as each new project's Postgres, so serverless functions that open a connection per request don't overwhelm the database.
- [How we scale PgBouncer in ClickHouse Managed Postgres](https://swe.quest/articles/how-we-scale-pgbouncer-in-clickhouse-managed-postgres-130231ec324c9f46.md): ClickHouse · 2026-07-01 · Medium · 4 min read · PostgreSQL, Performance engineering, Load balancing, Linux, Scaling
  Because PgBouncer is single-threaded, ClickHouse Managed Postgres runs a fleet of PgBouncer processes sized to the core count, all binding one port via so\_reuseport so the kernel load-balances connections behind a single endpoint.
- [PgDog vs. RDS Proxy](https://swe.quest/articles/pgdog-vs-rds-proxy-54748e0d30fc5847.md): PgDog · 2026-08-17 · Medium · 5 min read · PostgreSQL, Load balancing, Scaling, Cloud platforms, Performance engineering
  PgDog avoids RDS Proxy's connection pinning, which silently disables transaction pooling when apps use SET, temporary tables, advisory locks, or queries over 16 KB, and can exhaust Postgres connections.
- [Supavisor: Scaling Postgres to 1 Million Connections](https://swe.quest/articles/supavisor-scaling-postgres-to-1-million-connections-8585e4b9712f0334.md): Supabase · 2023-08-11 · Medium · 7 min read · PostgreSQL, Elixir & Erlang, Scaling, Multi-tenancy, Performance engineering
  Supavisor is a multi-tenant Postgres connection pooler written in Elixir that Supabase built to replace single-threaded PgBouncer.

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)
