(no title)
stevencorona | 2 years ago
This has been a really elegant and low-complexity way to get distributed pubsub without the complexity of running a distributed erlang cluster (which seems a lil bit painful in a K8S+Continuous Deploy world)
There -are- some big downsides to be aware of though.
1. You can't use PgBouncer w/ LISTEN/NOTIFY. This has been really painful because of the high memory overhead of a pgsql connection + elixir keeping a pool of open pgsql connections. The tried and true method of scaling here is to just use PgBouncer. We've kicked the can on this by vastly over-provisioning our pg instance, but this has cost $10s of thousands on the cloud. Of course, it's solvable (dedicated non-pgbouncer connection pool just for LISTEN/NOTIFY, for example), but painful to unwind.
2. The payload has a fixed size limit (8KB, IIRC). This has bitten us a few times!
Even though I really like pg_notify, I think that if I were starting over, I'd probably just use Redis Pub/Sub to accomplish the same thing. Tad bit more complex if you're not already running Redis, but without the downsides. (Of course, w/ Redis, you don't get the elegance of firing a notification via a pg trigger)
colinchartier|2 years ago
function software_listen(channel, callback):
function on_message(channel, data): function unlisten(channel, listener): Here's the actual go implementation we use:https://gist.github.com/ColinChartier/59633c1006407478168b52...
the_angry_angel|2 years ago
[1] https://github.com/postgresml/pgcat
chasers|2 years ago
If discovering nodes is difficult in your env, try using a listen/notify libcluster strategy:
https://github.com/supabase/supavisor/blob/main/lib/cluster/...
Dowwie|2 years ago
timwis|2 years ago
Background/announcement: https://supabase.com/blog/supabase-realtime-multiplayer-gene...
chasers|2 years ago
And we didn't want people schemas polluted with triggers.
But also we use Erlang distribution and Phoenix.PubSub because with a global network clients connected to the same node in the same region will get normal Broadcast messages to each other faster. If we ran them through Postgres or Redis the added latency wouldn't work for a global thing.
lawik|2 years ago
Dowwie|2 years ago
Nezteb|2 years ago
parthdesai|2 years ago
cpursley|2 years ago
gg2222|2 years ago