3 ms·
Hey HN, this is an Elixir server (Phoenix) that allows you to listen to changes in your database via websockets. Basically the Phoenix server 1. listens to Po
by kiwicopple 7y ago
Hey HN, this is an Elixir server (Phoenix) that allows you to listen to changes in your database via websockets.
Basically the Phoenix server
1. listens to PostgreSQL's native replication functionality (WAL stream)
2. converts the byte stream into JSON
3. it then broadcasts over websockets
I wrote this originally to replace Firebase's firestore database, which I wasn't too pleased with. I needed the realtime functionality for messaging inside my apps.
Thought the community here might like it. Postgres is an amazing database - with realtime functionality I was able to consolidate everything into one database.
Would love feedback. There are a few (many?) bugs and a lot of things to iron out, but I'm working with some close friends to make it awesome.
- shadowsun7 7y agoI know I’m late to the party, but I’ve recently come around to the idea of using apps that sit in front of Postgres to provide an API for free. This seems like an amazing project! I mean, I knew PostgREST existed, but I didn’t realise think it would be possible to make something similar that worked for the real-time use case. Brilliant stuff!
- kiwicopple 7y agoI really love PostgREST. This was my early approach to realtime, using PostgREST for CRUD operations: https://paul.copplest.one/blog/nimbus-tech-2019-04.html#tech-stack https://paul.copplest.one/blog/nimbus-tech-2019-04.html#tech... Not much is different now except I don't use NOTIFY anymore due to the 8000 byte payload limitation (and the reason why I made the elixir server)
- numtel 7y agoI got around the 8000 byte limit by sending multiple notifications in this NPM package: https://github.com/numtel/pg-live-select/blob/master/lib/trigger.tpl.sql#L42 https://github.com/numtel/pg-live-select/blob/master/lib/tri... Reading the replication log is probably faster though. MySQL has row-based replication too and there's clients in most languages if you want to support it on your saas. Do you have plans to support changes to specific SELECT queries or keep it at the row level?
- kiwicopple 7y agoThat's quite clever, I never actually thought of that. Guessing from your username, this is your package? It's very cool Yes, we will allow filtering on the listener, just shipping early. Next steps, we will only filter on the Primary keys - something like supabase.from('users:id.eq.1') - but eventually we will support advanced filtering like this: https://supabase.io/docs/library/get#filtering https://supabase.io/docs/library/get#filtering