Rxdb: A reactive database where you can subscribe to the result of a query
github.com
github.com
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 functionality and converts the byte stream into JSON which it then broadcasts over websockets. This is great since you can scale the Phoenix servers without any additional load on your DB. Also it doesn't require wal2json (a Postgres extension). The beauty of listening to the replication functionality is that you can make changes to your database from anywhere - your api, directly in the DB, via a console etc - and you will still receive the changes via Phoenix.
I still have to document a lot of how it works and how to use it, but if anyone is interested then I will make it a priority over the weekend
I'd seriously love to have query subscriptions, especially if the library is robust enough for use on mobile.
Ine large differentiator of Firebase's DB offerings is the subscription functionality, mobile and web, but using that means buying into NoSQL. A proper subscribable SQL database would be amazing.
Of course the conflict resolution on writes, and the local caching is another key benefit Firebase offers. Not sure how that could be done with a real relational DB!
FYI we are using this on our mobile (react native) in production, so I have no doubts it will be robust enough with a bit more polish
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:
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.
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
One of the motivating factors for not using triggers is that the implied overhead is very significant. By logging changes separately which triggers the write volume is roughly doubled, and the overhead of insertions is much much higher (a lot of fast/bulk path can't be used, the trigger processing needs to be performed).
Very true what you mention about trigger overhead. Also you don’t get guaranteed atomicity
Instead we have a bajillion layers of CRUD all in slightly different protocols just to do the same read or write to the database.
I mean, that's why it didn't catch on right :-) It's hard :-)
The "shard" could just be that users own feed in this case. Then you get offline for free where user adds a tweet and it appears immediately, replicating back to server when he goes back online. The server replica side will need to be a lot more complicated to deal with broadcasting but I don't see why it won't work.
Why not just load what is needed and hydrate the data over time? What about datasets where you need pagination/ordering etc. And the only way to guarantee order is to pull the whole set?
Of course, users with limited RAM and metered connections won't like that. Which is another reason why it didn't catch on.
If I had to make a Twitter clone with CouchDB, I would probably have one timeline document per user, and maybe one per day to limit the syncing bandwidth.
This breaks down quickly once you have data that could become private or mutate rather than append.
You do need to have you ACL data also stored in the database, which can be a hassle if you have existing ACL system already built outside of Firebase.
xrd, do you have a specific question about private data in Firestore?
In so many ways it is SO much easier to use Firebase because all the pieces are right there as compared to a DB + Server + Front End + Tooling. But, I still always worried that I would somehow leave a gaping hole in my data and not know about it.
And, I was never really sure how I can easily do joins across data without writing my own bespoke metalanguage inside Firebase. A link posted today on HN talked about XML does turn out to be good for nested data (hence the reason it is used for UIs), and it feels like Firebase being more or less JSON loses in this respect.
That's just my experiences, and I say that loving Firebase.
Those two examples made me think: Firebase removes a lot of complexity for me, but it forces me to write my own layer of complex access and DB logic which I never felt fully qualified to do, and as such, just went back to using databases with an ORM and a backend server.
The "one db per user" model for private data made using other features like views etc more difficult when you have to upgrade,edit,remove them.
Mutability wasn't really a problem, either present the conflicts to user and pick one or write code to merge if possible.
Permissions in general need to be handled by custom reconciliation functions (dropping unauthorized changes) or some kind of nanny system that can react to changes.
For example, imagine blog posts as documents, and a list of comments inside that document. Instead of the user adding/changing the comment list, the user would add a record to a comment request list, and either the reconciliation process or a nanny service checks the requests and updates the comment list.
The much simpler solution of course is to not let the users have any write access to the couchdb and just use a REST API. But then you loose much of the benefits of couchdb...
PouchDB is mentioned a couple of times, including one “PouchDB compatible” mention. Wondering what unique use cases RxDB supports?
If immutable fact/datom streams with idealized cache infrastructure becomes a thing (and architecturally i hope it does) it's going to need DRM to be accepted by both users and businesses.
As soon as your server state is larger than whatever your client can handle, the whole metaphor breaks down.
In 2015, my business implemented a Meteor-based real-time vehicle tracking app utilising Blaze, Iron Router, DDP, Pub/Sub
Our Meteor app runs 24hrs/day and handles hundreds of drivers tracking in every few seconds whilst publishing real-time updates and reports to many connected clients. Yes, this means Pub/Sub and DDP.
This is easily being handled by a single Node.js process on a commodity Linux server consuming a fraction of a single core’s available CPU power during peak periods, using only several hundred megabytes of RAM.
How was this achieved?
We chose to use Meteor with MySQL instead of MongoDB. When using the Meteor MySQL package, reactivity is triggered by the MySQL binary log instead of the MongoDB oplog. The MySQL package provides finer-grained control over reactivity by allowing you to provide your own custom trigger functions.
Accordingly, we put a lot of thought into our MySQL schema design and coded our custom trigger functions to be selective as possible to prevent SQL queries from being needlessly executed and wasting CPU, IO and network bandwidth by publishing redundant updates to the client.
In terms of scalability in general, are we limited to a single Node.js process? Absolutely not - we use Nginx to terminate the connection from the client and spread the load across multiple Node.js processes. Similarly, MySQL master-slave replication allows us to spread the load across a cluster of servers.
For those using MongoDB, a Meteor package named RedisOplog provides improved scalability with the assistance of Redis's pub/sub functionality.
Take a look at GraphQL, its central promise is to let client choose what's the optimal data it needs (that often denormalized through nested GraphQL queries), and send it in one batch.
It is not to say there shouldn't be a simple replica. It is just if we want it to be a simple replica, we should have a server-side mirrored some-what-denormalized representation rather than just the raw server-data models.
https://docs.hasura.io/1.0/graphql/manual/subscriptions/inde...
For anyone who wants something similar that's not GraphQL, then I'm in the early stages of developing a Phoenix (Elixir) implementation which broadcasts changes over websockets: https://github.com/supabase/realtime
See comments here: https://news.ycombinator.com/item?id=21354039
Demo vid https://v.usetapes.com/85knuAPruB Longer description in github readme https://github.com/jtmarmon/hackerthreads
Your example is similar to RethinkDB and others. A websocket streaming json.
[1]: https://github.com/tonsky/datascript
I have certainly created infinite loops while using React's componentDidUpdate, maybe it's just important to define triggers on single attributes rather than entire database rows.
RxDB does exactly one thing which is being a client side database. You are not tied to a specific ecosystem or backend database.
Anyway, database is hard, opensource is great. We love them both, RxDB or Meteor.
This is based on meteors oplog-observe-driver https://github.com/meteor/docs/blob/version-NEXT/long-form/o...
So basically when a change-event comes, RxDB does not run the query against the database again, but instead uses the old results together with the event to calculate the new results.
It basically registers itself as a fake replica server so that it can get updates from the master (like binlog in case of MySQL) and then it forwards those updates to Kafka. The possibilities are endless what you can do with those updates as Kafka consumers.
I suppose this could be the killer feature to warrant using a new database -- because otherwise, from a user point of view, the result is the same.
We used this for our mobile apps and the experience was pretty awesome. The ability to live observe both individual objects in the dB and results of queries makes building reactive UI’s a very pleasant experience.
I'm not doing field projects anymore but knowing this exists would have helped me tremendously in the last few years.
Thanks for sharing!
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.
Authentication is much easier when you use the GraphQL replication. There you are much more flexible on which data you return depending on which user is asking for it.
This is a nice feature for some, but not all situations..
Is there still maintenance?
https://github.com/rethinkdb/rethinkdb/issues/6747#issuecomm...
TLDR: They are hoping to announce a revival in the near future.
This project looks really awesome, and very much has the shape we wished Horizon could have turned into
EDIT: never mind, I should have read the article.
Are there triggers that run on every update on the dataset?
See also Google Wave, which had "real time" as its main novelty, but ultimately failed.
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.
or, even, "what is gun replacing?"
I mean, it looks interesting and I would like to play around with it, but I don't understand enough to know what kind of stuff I can build with it.
I also tried to understand the codebase which is impossible with obfuscated code like this one: https://github.com/amark/gun/blob/master/lib/store.js#L16
Here is a 5min interactive coding tutorial that shows that using GUN is more powerful than reading about GUN. https://gun.eco/docs/Todo-Dapp
For instance, Archive integrated in 1 week.
Notabug first version was built in 1 week with it. (p2p Reddit)
Organization can go a far ways in a short time.
I've used it in some projects and found it useful. Thanks.
I noticed an instant downvote. It's not the first time i see this behavior on rxdb comments.
I submit that being pedantic about such things is frequently its own form of pretension.