r/postgres • • 2d ago

Tools Self-hosted alternative to Neon's HTTP driver: query your own Postgres via fetch()

Connecting serverless and edge functions to self-hosted PostgreSQL can be tricky. Some runtimes have TCP limitations, and opening database connections on every invocation adds overhead.

Neon offers an HTTP driver for its platform, so I built HTTP PostgreSQL Gateway for self-hosted PostgreSQL.

It runs alongside your database and lets you query it using plain fetch().

  • Persistent PostgreSQL connection pooling
  • Scoped API keys mapped to PostgreSQL roles
  • Async queries for long-running operations, so functions don't have to wait for results
  • Atomic batches and transactions

It doesn't replace PostgreSQL or make queries faster. It handles connections and execution outside your serverless functions.

Security: It accepts client-supplied SQL, so use least-privilege roles and restrict network access. The project is new and hasn't had much external review yet.

Repo: https://github.com/http-postgres/http-postgres

How are you connecting self-hosted PostgreSQL to serverless or edge functions today? Feedback welcome.

2 Upvotes

2 comments sorted by

2

u/ivomitkittens 1d ago

What do you mean Cloudflare Workers can’t open TCP connections?  https://developers.cloudflare.com/workers/tutorials/postgres/

1

u/Savings-Feedback6581 1d ago

Sorry for the confusion. I meant that establishing PostgreSQL connections adds overhead, while the gateway reuses persistent connections through fetch(). For long-running joins, you can also receive a query ID and fetch the results later instead of keeping your serverless function running.