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!
IsoPhoenix
IsoPhoenixā€¢352d 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ā€¢352d 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ā€¢352d 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ā€¢352d 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ā€¢351d 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ā€¢344d ago
react query has auto refetching built in
Jim
Jimā€¢337d 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ā€¢337d 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ā€¢337d ago
Real time hooks are definitely in demand, you basically have ably and pusher that provide them but they are expensive
Keef
Keefā€¢337d ago
soketi
Soketi is your simple, fast, and resilient open-source WebSockets server. šŸ“£
Keef
Keefā€¢337d ago
Theres also this if you want to play around w it
Jim
Jimā€¢337d 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ā€¢337d ago
Yeah its kinda off topic my bad* but its just general advice at achieving this outside of planetscale
Jim
Jimā€¢337d ago
All good!
Keef
Keefā€¢337d 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ā€¢337d 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ā€¢337d 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
Drag and drop library recommendation?Whats the community-favorite option right now? I saw that react-beautiful-dnd isn't being maintainedtRPC invalid_type error with ClerkHi, I have this weird issue I've been trying to resolve for a while now. This is the error in browsSave selected option on dropdownHii, I have a dropdown list that is being made from an array and a Save button. When I click the savEnd-to-end testing tools, SuggestionsHey everyone! šŸ˜„ I hope you're all doing well. šŸ‘‹ I have a couple of questions for you, and I'd reN Nested RelationsHi im having trouble dealing with nested includes. I have a Comment and reply structure and replies A question on procedure design.I would like to know if it is best to try combine procedures or keep them separated. I don't want toMigrating to supabase from create-t3-turboHey guys! I'm migrating a create-t3-turbo app to the supabase create-t3-turbo template, and I'm a biSystem dark mode not detected when using darkMode: "media" in tailwind.config.tsHello! I am building a simple starter project using Tailwind and `shadcn-ui` components. I want the What is wrapping a next server action in startTransition doing?This was brought up in another question. I came up with the following explination, however this is jCan I call tRPC procedure inside another procedure?Something like this: ```js export const mainRouter = createTRPCRouter({ create: privateProcedure Anyone know how to go about using Tailwind Animation to animate a linethrough on hover?Or framer motion.Task scheduler infra?I'm looking for something that can do the following (or do essentially the same thing). It feels likNeed suggestions for better infra CICDalright, so for this project i use docker containers for everything. my compose file has a redis cacConditional render, why can't it be done?I understand the reason this happens it that *something* doesn't understand that the Loader already do something once server action is completedIs there a way to achieve this (see title)? Iā€™m using useTransition to start the action and need to How to use discord.js in Nextjs app dirHello, I am trying to use discord.js in my app but getting alot of errors, is this even possible?: `best way to fetch data in nextjsI was wondering what's the best way at the moment to query for external apis in NextJS? I know that @next/font turbo t3You might be using incompatible version of `@next/font` (13.4.4) and `next` (13.1.6). what version sTypescript issue causing trpc functions to not have type checkingHey, I'm in a create-t3-turbo app and have been banging my head against the wall trying to figure ouClerk middleware breaks Discord URL preview (embed)Anyone know how to fix this ...?