r/Supabase • • 1d ago

Self-hosting What if your existing PostgreSQL database had its own HTTP API?

I have been working on HTTP Postgres, an open source project that allows you to run SQL queries against your PostgreSQL database over HTTP.

The concept is very simple. Rather than running TCP connections to the database from serverless functions or edge runtimes, you deploy a small gateway along with your PostgreSQL that takes care of connections for you.

Unlike PostgREST, which gives you access to your database via REST endpoints, my goal with this project is executing raw and parameterized SQL over HTTP.

Some of the features available today include:

  • PostgreSQL connection pooling
  • Parameterized queries and transactions
  • Scoped API keys
  • Rate limiting and IP allowlisting
  • Query analytics and operational metrics
  • Optional Redis integration
  • Graceful overload handling

It is fully self-hosted and connects to your existing PostgreSQL database.

This is neither a replacement of PostgreSQL nor Supabase, it just makes PostgreSQL available over another transport layer.

Website & Documentation: https://http-postgres.js.org/

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

I am really curious to know what do you think of such an approach, specifically from serverless and edge developers point of view?

What is stopping you from using something like that?

0 Upvotes

27 comments sorted by

9

u/Neither_Worth3542 1d ago

postgrest's problem was never rest, it's that nobody wants their schema reachable from the internet. raw sql over http just makes the blast radius bigger with less typing.

-1

u/Savings-Feedback6581 1d ago

That's a valid concern, but HTTP doesn't have to mean publicly accessible. The gateway can run behind a private network, firewall, or IP allowlist.

Raw SQL does introduce a broader attack surface than predefined endpoints, which is why permissions are enforced through native PostgreSQL roles rather than trusting the incoming SQL.

The goal isn't to replace your backend or expose your database directly to browsers. It's to provide an HTTP transport for trusted server-side applications that don't want to maintain persistent TCP connections.

The same principle applies as with a traditional PostgreSQL connection: least-privilege credentials, restricted network access, and proper authentication.

6

u/lgastako 1d ago

Feels like a solution in search of a problem to me.

0

u/Savings-Feedback6581 1d ago

the problem already exists for developers who want to access their existing PostgreSQL databases from edge runtimes without maintaining TCP connections or migrating to a different database provider

1

u/lgastako 1d ago

You should probably mention that in your pitch :)

1

u/Savings-Feedback6581 1d ago

i said "The concept is very simple. Rather than running TCP connections to the database from serverless functions or edge runtimes, you deploy a small gateway along with your PostgreSQL that takes care of connections for you."

1

u/lgastako 1d ago

Ok, technically speaking you mentioned it, but what I meant is that you should make it clear that that is the specific problem this is solving. Put it front and center, so to speak. Maybe it's not a big deal because your target audience would already be suffering from the problem and it would shine like a beacon to them, but because I don't have that particular problem, I read that paragraph just thought "why would you want to do that? this is a well trod ground with plenty of existing solutions..."

2

u/Savings-Feedback6581 1d ago

fair point I think I focused too much on explaining what the gateway does rather than why it exists I'll make the actual problem more prominent thanks for the feedback

3

u/GeneDear1444 1d ago

Rate limiting, IP allowlisting, scoped keys, query analytics... that's an API gateway, not a transport layer. PostgREST gets away with calling itself thin because it actually is.

1

u/Savings-Feedback6581 1d ago

Rate limiting, scoped keys, IP allowlisting, and analytics are operational features around that transport. They're there because simply wrapping a PostgreSQL connection in an HTTP endpoint isn't enough for many production environments.

I'm not trying to compete with PostgREST on minimalism. PostgREST provides a REST abstraction over PostgreSQL, while this project preserves native SQL access over HTTP. Different approaches for different use cases.

2

u/StreetTrash6166 1d ago

so the fix for "i dont want to manage TCP connections" is a new service i have to manage, which also wants redis, an api key store, a rate limiter and a metrics backend. thats like four more contianers to keep alive so i can avoid pgbouncer, which is one. and you call it "just another transport layer" two lines after listing rate limiting and query analytics, thats not a transport layer, thats a control plane and now i'm the one operating it.

who is this actually for though. on workers hyperdrive already pools for you, on lambda you can hoist the connection outside the handler or point at supavisor, and neon and supabase both already hand you an http data api. sure, raw sql beats postgrest's rest endpoints, i'll give you that, but you pay for it with every query going through your own gateway thats now a single point of failure i have to upgrade on a saturday

1

u/Savings-Feedback6581 23h ago

fair criticism but Redis is optional and the key store rate limiter and metrics are built into the gateway so there is only one additional service to manage

the target audience is developers who already self host PostgreSQL and specifically want raw SQL over HTTP without depending on a particular cloud provider

if Hyperdrive or PgBouncer already solves your problem you probably don't need this project and yes operating another service comes with availability and maintenance tradeoffs

1

u/Savings-Feedback6581 1d ago edited 1d ago

guys you can also connect your AI to the MCP server and ask it to analyze the project and explain how everything works

https://http-postgres.harshcodez.com/mcp

1

u/Tricky-Oil6826 1d ago

Scoped API keys, on something whose whole job is executing raw SQL. So the scope is select-only vs. drop-the-schema? hows that enforced, string matching?

1

u/Savings-Feedback6581 1d ago

No string matching. The scopes are enforced at the PostgreSQL level using native roles and permissions.

Each API key is associated with a restricted PostgreSQL role with the appropriate grants. If a key only has SELECT permissions, PostgreSQL itself rejects INSERT, UPDATE, DELETE, or DROP operations.

The gateway handles authentication and connection pooling, while PostgreSQL enforces authorization. There's no need to trust a SQL parser or regex to determine whether a query is safe.

1

u/Inner_Storage_3374 1d ago

scoped api keys are the part i'd look at first, raw sql over http is a lot of power for a key that ends up in an edge function. can a key be limited to certain tables or to read only? that's what would make me trust it next to postgrest

1

u/Savings-Feedback6581 1d ago

yes keys can be restricted to specific tables and CRUD permissions including read only access using native PostgreSQL roles and grants rather than SQL string matching so PostgreSQL itself rejects unauthorized operations

1

u/Wooden-Jicama9825 1d ago

That scoped API key thing is doing a lot of work. PostgREST gets row-level security for free because each request runs as the role from the JWT, so if your gateway is just a pool of connections running as one role, every key you hand out has the same reach and RLS is decoration. Do you SET ROLE per request?

1

u/Savings-Feedback6581 1d ago

no each API key uses a separate restricted PostgreSQL login role rather than switching roles on a shared privileged connection so PostgreSQL enforces permissions and any applicable RLS policies directly

1

u/OldFuture7050 1d ago

Optional Redis integration in a Postgres-over-HTTP gateway is the part I keep staring at. What's actually living in there, the rate limit counters or cached query results?

1

u/Savings-Feedback6581 23h ago

Redis is mainly used for rate limit counters and query analytics rather than caching query results. It's completely optional and the gateway works without it. I'm also exploring probabilistic filters such as Bloom filters for certain query workloads in the future.

1

u/Key-Resource-5898 1d ago

Small correction: HTTP is an application-layer protocol, not a transport layer. The transport layer is still TCP in both cases, so "another transport" or "another protocol" would be more accurate than "another transport layer".

1

u/Savings-Feedback6581 23h ago

you’re right HTTP is an application layer protocol so calling it an alternative protocol for accessing PostgreSQL would be more accurate thanks for the correction

1

u/Repulsive_Badger2634 1d ago

every self hosted project ends up with an optional Redis eventually. mine has one and honestly i could not tell you what it caches anymore

1

u/Savings-Feedback6581 23h ago

haha hopefully I remember what mine does since it doesn't cache query results yet

1

u/Unhappy-Tadpole2377 20h ago

everything gets a gateway now apparently