Live data from Hacker News

Rxdb: A reactive database where you can subscribe to the result of a query

github.com

81–90 of 126 posts

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#81

You can do this in datomic! I made an end-to-end proof of concept of this using datomic and websockets. The client can open a websocket and subscribe to a query and then the server will react to changes in the database and automatically update the model and therefore the UI (no eventing code required). Demo vid https://v.usetapes.com/85knuAPruB Longer description in github readme https://github.com/jtmarmon/hackerthr…

I think you have not understood what RxDB is. It is a client side database. It works also when the client is offline. It does not need a stable internet connection over a websocket.

Your example is similar to RethinkDB and others. A websocket streaming json.

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#82
What I personally like about RxDB is that it also works completely offline. However, I don't really understand encryption: As far as I understood, it encrypts on the client side with the db passwort which is sent to the server.

Another issue is Authorization and Authentication, I could not find a good solution for me for CouchDB. Couchbase seems to have better solutions for this but the premium plan seems really expensive and as far as I understood you need a "server" and a "sync server" which don't have low system requirements, at least for me.

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#83

I have been developing something that provides this functionality for PostgreSQL: https://github.com/supabase/realtime It's still in very early stages (although I am using it in production for my company) It's very similar to Debezium (mentioned in another comment), but it's built with Phoenix (elixir), so great for listening via websockets. Basically the Phoenix server listens to PostgreSQL's replication functionali…

Interesting, thanks for sharing how you're doing it.

Is there any mileage in doing this with triggers? I have a _very_ legacy system which needs caching adding. Rather than dig through the code to invalidate the cache every time a record is updated/deleted in 20+ tables, I am thinking that being able to listen to the SQL executed and invalidate the cache based on the tables involved would be a clean approach.

But not found any way to make that possible - yet.

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#85

There is also (mine) https://github.com/amark/gun It is run by Internet Archive, HackerNoon, DTube, Notabug, etc. Handles about 8M monthly active users! + end-to-end encryption, graphQL & graph data, upcoming Svelte support, decentralized, etc. MIT/Zlib/Apache2 licensed.

Gun is essentially similar to Firebase[0]

I've used it in some projects and found it useful. Thanks.

[0]: https://firebase.google.com/

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#86
post #59

General question about reacting to database events: It seems like when responding to DB events it would be easy to accidentally create an infinite loop. Is that an issue with this pattern, or is it easy to avoid? Do any of these data subscription tools have safeguards in place to prevent this?

Naively it sounds like the halting problem. You would have to verify that no consumer can make a change to the data set you are listening to. You would want to manage yourself when not to respond to an event.

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#87
post #83

I have been developing something that provides this functionality for PostgreSQL: https://github.com/supabase/realtime It's still in very early stages (although I am using it in production for my company) It's very similar to Debezium (mentioned in another comment), but it's built with Phoenix (elixir), so great for listening via websockets. Basically the Phoenix server listens to PostgreSQL's replication functionali…

Interesting, thanks for sharing how you're doing it. Is there any mileage in doing this with triggers? I have a _very_ legacy system which needs caching adding. Rather than dig through the code to invalidate the cache every time a record is updated/deleted in 20+ tables, I am thinking that being able to listen to the SQL executed and invalidate the cache based on the tables involved would be a clean approach. But not…

Yeah I also used triggers at the start. There are 2 things that this implementation achieve over triggers.

1. Triggers have an 8000 byte limit. I ran against these limits pretty quickly

2. You need to attach the trigger each time you create a new table. With this you can set and forget

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#88

I have been developing something that provides this functionality for PostgreSQL: https://github.com/supabase/realtime It's still in very early stages (although I am using it in production for my company) It's very similar to Debezium (mentioned in another comment), but it's built with Phoenix (elixir), so great for listening via websockets. Basically the Phoenix server listens to PostgreSQL's replication functionali…

RethinkDB might be another database to look at if this is functionality which you are interested in. My only gripe with doing this sort of thing is that if you offer a public API, it becomes separate to what you are using for the application internally. There are also some GraphQL databases like Prisma that offer this sort of functionality.

I actually used Firebase at the start but this implementation is so that we can migrate 100% to Postgres. I agree though, Rethink is awesome

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#89
post #10

Earlier quoted context omitted.

When your data is public and immutable, this approach is very pleasant. The client becomes just another caching layer and worst case it's presenting a historical version of the truth. You can even extend this across tabs with things like local storage. This breaks down quickly once you have data that could become private or mutate rather than append.

I think the Firebase Realtime Database and Firestore have a good model for offline and being able to have private and mutable data. It does get complex but the Firebase SDKs do the heavy lifting for you here.

Can you share more about the private and mutable data functionality for Firebase? I used them a few years back, and never really understood how to do private data without building my own ACL inside Firebase.

Re: Rxdb: A reactive database where you can subscribe to the result of a query

#90
post #75

I have been developing something that provides this functionality for PostgreSQL: https://github.com/supabase/realtime It's still in very early stages (although I am using it in production for my company) It's very similar to Debezium (mentioned in another comment), but it's built with Phoenix (elixir), so great for listening via websockets. Basically the Phoenix server listens to PostgreSQL's replication functionali…

Did you evaluate gRPC or gRPC-Web when considering your websockets implementation? I'm using gRPC in other languages/frameworks and I'd really like to migrate one of those to Elixir in the near future, but I'm curious to know if anyone else has given it a try. There's a prominent warning on the repo: https://github.com/elixir-grpc/grpc

I didn’t try, to be honest i think the implementation of this might be beyond my elixir capabilities. But I’ll check it out - thanks for the link!
Post reply on HN