News for hackers. Stuff that matters.
Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Friday October 25, 2019 @07:52AM (#21354039)
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 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

Re:Rxdb: A reactive database where you can subscribe to the ... by dsun180 on Friday October 25, 2019 @07:54AM (#21354054)
There is a big difference between the changestream of many SQL and noSQL databases, and what RxDB does. Having a stream of changes is useful but not the whole solution. RxDB is capable of using single document changes of a stream and recalculate the new results of an existing query. This saves you not only much IO performance but makes developing much easier. See https://rxdb.info/query-change-detection.html
Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Friday October 25, 2019 @08:10AM (#21354154)
Yeah perhaps "same functionality" is an ambitious statement. I just saw debezium mentioned below and thought i'd throw this out in case someone reading this and it fits their needs!
Re:Rxdb: A reactive database where you can subscribe to the ... by tjchear on Friday October 25, 2019 @04:21PM (#21358870)
I would love to use this just for the offline and query change detection capabilities alone - but the latter is currently beta and disabled by default. Is there a reason for that?
Re:Rxdb: A reactive database where you can subscribe to the ... by cryptonector on Friday October 25, 2019 @04:44PM (#21359071)
I do this sort of thing with triggers and table-based materializations of views.
Re:Rxdb: A reactive database where you can subscribe to the ... by markandrewj on Friday October 25, 2019 @10:15AM (#21355134)
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.
Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Friday October 25, 2019 @01:35PM (#21357308)
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 ... by com2kid on Friday October 25, 2019 @04:23PM (#21358894)
Make this good enough and you could very well cut into a huge chunk of Firebase's business model.

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!

Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Saturday October 26, 2019 @12:46AM (#21361777)
Thanks for the comments. I agree, the conflict resolution of FB on mobile is pretty awesome.

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

Re:Rxdb: A reactive database where you can subscribe to the ... by markandrewj on Friday October 25, 2019 @02:57PM (#21358098)
Just out of curiosity, are you moving off of Firebase because of technical limitations, or because of pricing?
Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Friday October 25, 2019 @03:51PM (#21358606)
Mainly because I want to keep my team small so it’s easier if we all commit to Postgres. But We also hard a hard time with Firebase’s filtering on sub collections (for their new Firestore)
Re:Rxdb: A reactive database where you can subscribe to the ... by markandrewj on Friday October 25, 2019 @05:49PM (#21359572)
Fair enough.
Re:Rxdb: A reactive database where you can subscribe to the ... by pbowyer on Friday October 25, 2019 @12:21PM (#21356503)
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 ... by kiwicopple on Friday October 25, 2019 @01:33PM (#21357286)
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 ... by anarazel on Friday October 25, 2019 @01:57PM (#21357517)
There's no 8k limit with triggers? Could you expect on what you mean by that?

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).

Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Friday October 25, 2019 @02:05PM (#21357591)
Sorry I meant I was using triggers to sent a NOTIFY which has an 8k byte limit.

Very true what you mention about trigger overhead. Also you don’t get guaranteed atomicity

Re:Rxdb: A reactive database where you can subscribe to the ... by numtel on Saturday October 26, 2019 @10:10PM (#21367483)
I wrote a node.js package a few years ago that gets past the 8000 bytes by sending multiple notifications.

https://github.com/numtel/pg-live-select

Re:Rxdb: A reactive database where you can subscribe to the ... by ronmex on Friday October 25, 2019 @04:35PM (#21358993)
You can use apache ignite as a caching layer over your db. (Or as a db itself). You can then register a ContinuousQuery to listen for changes. A grpc service can be stood up to stream these changes to other clients, even front end ones (via grpc-web).
Re:Rxdb: A reactive database where you can subscribe to the ... by rch on Friday October 25, 2019 @11:43AM (#21356109)
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

Re:Rxdb: A reactive database where you can subscribe to the ... by kiwicopple on Friday October 25, 2019 @01:38PM (#21357335)
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!