How is realtime DB syncing accomplished without Firestore/Supabase?

Hi! I've been working with Firestore for a long time now and gotten very used to the realtime db syncing functionality it provides, although I'm trying to move away from Firestore now. Supabase is an obvious alternative because it also provides realtime functionality, but I'm wondering if there's any other way DB syncing might be accomplished (say, if I'm using PlanetScale). If I'm using Planetscale as a DB and, say, viewing data from the database on the webapp, and a different user updates the data, is there a way for me to receive the update on my end (without refreshing)? Thanks!
17 Replies
IsoPhoenix
IsoPhoenix•15mo ago
^^ planetscale is just a specific example, but I'm basically wondering about any DB option that doesn't explicitly provide a realtime client like Firestore or Supabase.
Aland
Aland•15mo ago
Realtime DB syncing is complicated, only way to make it work with postgres/mysql is by implementing it on your own with websockets.
IsoPhoenix
IsoPhoenix•15mo ago
@alandsleman thank you so much! Is there an easy way to accomplish, like, "near-realtime" functionality with the T3 stack, such as by intermittent polling of queries (or something of that nature)?
thevalorised
thevalorised•15mo ago
You can always put your queries in a setInterval block but it is extremely wasteful and a practice I would avoid at all costs
hutajoullach
hutajoullach•15mo ago
@IsoPhoenix If you are not looking to implement a bidirectional connection between db and client, try react query. T3 app is using react query under the hood and on top of that, you can use react query within T3 app as well. You should have access to the boolean value "isStale", so just create a condition to check if data is stale, and then call "refetch" function if the data is indeed stale. Also, with next.js, useSWR will do the same but generally you can achieve what you want with react query.
dan
dan•14mo ago
react query has auto refetching built in
Jim
Jim•14mo ago
I'm running into the same issue with pscale. https://github.com/planetscale/discussion/discussions/119 The only work around is polling, which is blunt and expensive. I'm surprised realtime hooks aren't in demand. My use case is digital signage dashboards and kiosk apps so maybe i'm in a minority, but I would have thought listening to table updates would have a wide scope of uses. Did you find any solutions? @IsoPhoenix
GitHub
CDC from planetscale · planetscale discussion · Discussion #119
Is there already a solution for or plans to implement a feature that would allow change data capture with planetscale? i.e. deliver an event to my application with the changed data when a row is up...
Keef
Keef•14mo ago
Postgres has listeners that when combined with a trigger you can spin off an event then consume it on your application. https://www.postgresql.org/docs/8.4/catalog-pg-listener.html I usually have a backend service that would listen for these events then handle the publish into a websocket that the front end consumes otherwise your only other options is gonna be polling.
PostgreSQL Documentation
pg_listener
Keef
Keef•14mo ago
Real time hooks are definitely in demand, you basically have ably and pusher that provide them but they are expensive
Keef
Keef•14mo ago
soketi
Soketi is your simple, fast, and resilient open-source WebSockets server. 📣
Keef
Keef•14mo ago
Theres also this if you want to play around w it
Jim
Jim•14mo ago
Thanks for the response keef. I was looking at the pub/sub services yesterday but didnt understand how they worked looking at the examples. Since there is no CDC/webhooks on planetscale how do they know when theres been an update. I suppose maybe you could run a seperate db which you call anytime you make updates to a pscale table and listen to that instead 🤔
Keef
Keef•14mo ago
Yeah its kinda off topic my bad* but its just general advice at achieving this outside of planetscale
Jim
Jim•14mo ago
All good!
Keef
Keef•14mo ago
Polling is kinda gross but it does the job when your service doesn't help you in achieving what you need shyfingers
Jim
Jim•14mo ago
Yeahhh, im sure they'll figure a solution out in the coming months, I think for now I'll have to stick with supabase and miss out on the cool forking action :~) Thanks for clearing that up for me though, I was obsessively looking for a solution that wasnt there lol
Keef
Keef•14mo ago
eh its not much of solution tbh lol just sharing it bc it may be useful
Want results from more Discord servers?
Add your server
More Posts