Listen to your to PostgreSQL database in realtime via WebSockets
github.com
github.com
Two of the other reasons for this over triggers are also misleading:
- Setting up triggers can be automated easily.
- True, you only use 1 connection to the database, but you now operate this app. You could also run pgbouncer.
This is how I design all my table schema. and it make database partitioning easier too.
I'd love to just just have "A-B-C" as my Cs' IDs... but it'd only work for my use-case (i.e. be performant) if it was running on a computer with 256-bit registers.
Also having a single compound index on table C covering column (A ForeingKey, B ForeingKey, C GUID) is much better than having multiple index on table C.
It generate tens of thousands of ids per second. Those id fit in 64 bits. And those id are sortable, meaning that if tweets A and B are posted around the same time, they should have ids in close proximity to one another.
See: https://blog.twitter.com/engineering/en_us/a/2010/announcing...
It's just that in my experience have the children table primary b-tree sorted on ParentID then childrenID make join much more efficient unless you can use table interleaving like in Google SpannerDB https://cloud.google.com/spanner/docs/schema-and-data-model#...
The actual purpose is actually way cooler, looks like a great tool
I think a recording of this is actually built into Pagerduty to use as a sound when you're getting paged. I went with the "golf ball hit into a flock of geese" one, though. Every time that goes off my first thought is "OH GOD I'M DYING HELP" but then I look and it's just GCP down again. Ironically therapeutic.
http://peep.sourceforge.net/intro.html https://www.usenix.org/legacy/publications/library/proceedin...
I guess someone needs to do it now, hm...
(But: I think live db-activity rendered to music as a kind of monitoring mechanism is potentially way cooler than just getting db updates over a web socket.)
Listen to packets on /dev/audio (warning: can be noisy).
https://docs.oracle.com/cd/E23823_01/html/816-5166/snoop-1m....
When we were learning Linux a friend and I used to pipe /dev/hda into /dev/dsp for fun and when we hit some fragments of uncompressed piano recordings we joked that we must have hit the kernel source code. Good times.
"Stockify is a live music service that follows the mood of the stock markets. It plays happy music only when the stock is going up and sad music when it’s going down." https://vimeo.com/310372406
(it's of course a parody, but I made a functional prototype)
Also, if you haven't read Douglas Adam's "Dirk Gently's Holistic Detective Agency", there's a good subplot around this exact idea.
With Fauna you still get vendor lock-in though.
Postgrest (which is basically what Supabase is, obviously with other value-adds) or Hasura which basically exposes a GraphQL server that interfaces with Postgres.
Personally I prefer GraphQL as there's more tooling around that compared to Postgrest but it's interesting to see. In this case if supabase was GraphQL you could just use a subscription.
I'd be curious to know why supabase didn't go with GraphQL.
I'm guessing because GraphQL is very limited compared to SQL.
From reading their docs [1] it seems they have a JS API for SQL with support for nested data a la GraphQL. Not sure if its their own or comes from some other library.
Using a few commonly-used add-ons, you can write a whole lot of sql in gql and it Just Works, translating your deeply-nested and richly-filtered gql query into a single, performant sql query.
You can see roughly how this translation ends up here: https://gist.github.com/rattrayalex/ae39c2cf0356f1257ece4f3c... (in production it's more condensed etc).
You can also extend with sql functions or add/wrap resolvers at the js level. (And yes, you can easily hide columns, rename, etc)
My only gripe with postgraphile is not supporting column grants in RLS policy.[0] Instead they recommend splitting tables in two and having one-to-one foreign keys and using grants on the full tables instead. It's a shame because PostgREST dealt with column grants just fine and I don't want to use postgraphile's specific "smart comments" in my database, they just seem like a really un-elegant solution to what is otherwise a super nice pattern: SQL everything.
I also considered Hasura but they have their own auth system and don't use RLS, which is a shame. Having access control in the database is super great when you have multiple APIs and different people with psql and different roles, all with different levels of access to the same DB.
0 : > Don't use column-based SELECT grants: column-based grants work well for INSERT and UPDATE (especially when combined with --no-ignore-rbac!), but they don't make sense for DELETE and they cause issues when used with SELECT. https://www.graphile.org/postgraphile/requirements/
But once you're polling a large percentage of your whole data set, the bin log approach has a clear advantage.
We're not opposed to GraphQL at all. We use PostgREST because it's very low-level. It's a thin wrapper around Postgres. It uses Row Level Security, works nicely with Stored Procedures, and postgres extensions (like PostGIS).
Philosophically we want to focus more on the database-centric solutions, rather than than middleware-centric solutions. This means a slower time-to-market, but it's beneficial because you have a "source" right at the bottom of your stack, and you can connect whatever tools you want to it (including Hasura!)
1- subscribe to event and buffer event
2- run SQL query for your materialized view
3- apply all buffered event and new event to incrementally update the materialized view
this way the (slow/expensive) query of the materialized view don't need to be run periodically and your cache always is always fresh without need to set TTL.
If you websocket connection get disconnected, drop the materialized view and repeat step #1.
No one is going to remove subscriptions.
https://github.com/apollographql/apollo-server/issues/2360#i...
https://github.com/apollographql/apollo-server/issues/2360#i...
They aren't trying to delete the feature itself, just roll it into their abstractions
It sounds like it's the latter, which seems like an unusual use case for websockets. (or at least I can't think of anything else that does ws for a server-to-server API)
- cheap framing
- bidirectional comms
- are already exposing an HTTP port
- can make no assumptions about the client's networking than port 443 available, even if only via a HTTPS proxy
- can make no assumptions about the client's software except they can speak an extremely common protocol
- want security to work the same way it does for the rest of your services
"web-scale" doesn't come into it. Websockets are inherently difficult to scale because they're stateful, but in return you get the lowest latency in both directions the underlying network can provide with extremely reasonable (2-4 bytes) overhead compared to raw TCP or SSL
Can you go in the other direction, ie push via WS into a table? Obviously you'd need the correct auth.
I had an idea of doing something similar with MQTT. Data at rest and data in motion in 1 (or maybe 1.5) components.
I implemented a portion of crud with a vuejs app. It's a pretty neat setup. Just authorize with OAuth2 and then if you have permissions youre good to go!
That is something that's on the roadmap though: https://github.com/benbjohnson/litestream/issues/129
Which one would you recommend for small-ish (~100 user, <10k records) projects?
I'm always wary of getting stuck in the "I wish I didn't use NoSQL" camp, but thankfully I haven't been in that situation yet
Using this tech or something more primitive?
I want to get some end user feedback on predictive model outputs...