Introduction
Introduction to HTTP PostgreSQL Gateway
HTTP PostgreSQL Gateway is a persistent bridge between HTTP-only runtimes and PostgreSQL. It allows serverless and edge clients to make stateless HTTPS requests while the gateway maintains reusable PostgreSQL connection pools on a private network where TCP or Unix-socket database access is available.
The Serverless Database Dilemma
Serverless platforms like Cloudflare Workers, Vercel Functions, AWS Lambda, Deno Deploy, and Bun present unique operational challenges when connecting directly to relational databases:
- No Direct Socket Support: Many edge runtimes (such as V8 isolates) cannot open raw TCP sockets to PostgreSQL.
- Connection Storms: Each serverless instance opens its own TCP connection. Spikes in concurrent traffic can quickly exhaust PostgreSQL's
max_connectionslimit. - Expensive TLS Handshakes: Re-establishing TLS connections and authenticating with PostgreSQL on every cold start introduces significant latency.
- Distributed Database Secrets: Storing master database credentials inside numerous client-side or distributed deployment configs increases exposure risk.
HTTP PostgreSQL Gateway solves these problems by providing a high-performance HTTP front-end that lives close to PostgreSQL, manages the backend connection lifecycle, and enforces strict authorization.
Core Capabilities
DISCARD ALL rollbacks and resets.c, r, u, d).Idempotency-Key headers to guarantee exactly-once commit behavior.Architecture at a Glance
flowchart LR
Client["Serverless / Edge Client<br/>(fetch)"]
subgraph Gateway["HTTP PostgreSQL Gateway (Fastify)"]
direction TB
Auth["Auth & Rate Limiting<br/>(Redis / Memory)"]
AdminPool["PostgreSQL Admin Pool<br/>(Migrations & Roles)"]
QueryPools["Per-Key Query Pools<br/>(Verified Sessions)"]
Metadata[("JSON Metadata Store")]
Analytics[("SQLite Analytics Worker")]
end
Postgres[("PostgreSQL Cluster<br/>(Private Network)")]
Client ==>|"HTTPS + JSON"| Auth
Auth --> AdminPool
Auth --> QueryPools
Auth --> Metadata
Auth -.-> Analytics
AdminPool ==>|"Admin TCP"| Postgres
QueryPools ==>|"Scoped TCP"| Postgres
The service separates administrative database access from client query access. API-key scopes are translated directly into PostgreSQL roles, ensuring that PostgreSQL remains the ultimate authorization boundary for SQL execution.
Gateway vs. Other Solutions
| Feature | Direct Driver | PgBouncer / Pgpool | HTTP PostgreSQL Gateway |
|---|---|---|---|
| Protocol | Native TCP | Native TCP | HTTPS / JSON (fetch()) |
| Edge Isolation Friendly | No (requires TCP) | No (requires TCP) | Yes (Native HTTP) |
| Credential Distribution | DB passwords in functions | DB passwords in functions | Scoped Bearer API Keys |
| Authorization Boundary | Client SQL string | Client SQL string | PostgreSQL Role per Scope |
| Async Execution | None | None | Yes (Persistent background queue) |
| Idempotent Transactions | Client managed | Client managed | Yes (Idempotency-Key tracking) |
| Failed SQL Sanitization | Application logs | Raw logs | Yes (Auto-redacted analytics) |
Next Steps
- Follow the Quickstart Guide to run the gateway locally in 5 minutes.
- Learn about the Serverless Integration Pattern and review the Minimal Client.
- Explore all supported execution methods in the API Routes Reference.
- Inspect the Security Hardening Guide before deploying to production.
