TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Projections as an Alternative to HTTP APIs

8 pointsby xkyalmost 3 years ago
I work at a large FinTech in a team responsible for a federated GraphQL service and, recently, related datasets in Redshift. We&#x27;ve come to see our datasets as another kind of API representing the same underlying data from our GraphQL API.<p>Our service is event sourced and follows CQRS and so our Redshift dataset is just another projection. This got me thinking, can other services simply use this projection directly instead of a GraphQL or REST API?<p>In general, services could provide an API for mutations that updates a projection which other services can directly query using SQL. Although services are accessing a database directly, it&#x27;s not breaking encapsulation because the data is a projection intended for use by other services like an API.<p>There&#x27;s a few benefits I see here. Firstly, if all services were modelled like this, querying multiple &quot;services&quot; could be handled with simple joins. Latency is reduced as data doesn&#x27;t pass through an intermediate service. Scaling reads is straightforward. The same &quot;API&quot; works for both transactional and analytical use-cases. And finally, low-write services could be scaled down and no-write services could just be data pipelines.<p>So HN what do you think about a database as a service API?

4 comments

SahAssaralmost 3 years ago
I&#x27;ve experimented with this as an alternative API layer. When using role-based RLS in postgresql and being strict with what is exposed to application users it can be quite nice, but it also brings in a lot of additional considerations. Things like rate-limiting, caching, timeouts, access logging, etc. are all very much standard practice on a HTTP or RPC layer, but not so much for a SQL interface. When using postgrest (a REST layer on top of postgresql) I&#x27;ve considered just exposing the same API over SQL since I already have the authZ fully implemented in the DB but I still don&#x27;t know if I want to implement everything else that goes along with a api in the DB.
jollyllamaalmost 3 years ago
This works fine as long as the data flow is one directional. E.g. legacy backend -&gt; db -&gt; read-only frontend<p>However once the frontend and backend begin to mutate data, you&#x27;re going to have problems doing that consistently; it&#x27;s an anti-pattern I recommend against. Better to have an API handle everything.
sitkackalmost 3 years ago
If you can guarantee that you get the same result for the same projection (a query and or rest call also could be characterized as a projection) then I don&#x27;t see an issue.<p>LOTS of rest services are just urls params -&gt; sql -&gt; result set -&gt; json<p><a href="https:&#x2F;&#x2F;postgrest.org&#x2F;en&#x2F;stable&#x2F;" rel="nofollow">https:&#x2F;&#x2F;postgrest.org&#x2F;en&#x2F;stable&#x2F;</a><p>Isn&#x27;t this what graphql was supposed to offer?
评论 #32348367 未加载
lesserknowndanalmost 3 years ago
You may be interested in an open source project I am developing, see: <a href="https:&#x2F;&#x2F;webapibridge.org" rel="nofollow">https:&#x2F;&#x2F;webapibridge.org</a><p>Web API calls are converted into MySQL Stored Procedure calls and the result set returned. I am interested in extending this to other databases.
评论 #32337217 未加载