Realtime Postgres Row Level Security
Hey HN, Supabase is an open source Firebase alternative. We're building the features of Firebase using enterprise-grade open source tools. We're particularly focused on scalability. We take proven tools like Postgres, and we make them as easy to use as Firebase.<p>Today, Supabase is adding Row Level Security (RLS) to our Realtime engine.<p>The linked blog post goes into depth around the technical implementation, so I’ll just give a recap for the people who jump straight to comments (like me).<p>Supabase was launched here on HN when we open sourced our Realtime engine[0] - an Elixir server which clients (i.e. website visitors/users) can connect to via websockets and receive a stream of PostgreSQL changes.<p>The server receives those changes via a logical replication slot - the same system that PostgreSQL uses for replicating to other databases.<p>To achieve RLS we added a few SQL functions, the main one is apply_rls[1] which the stream is filtered through. For every user connected to the Elixir server, the Postgres function checks if they have access to the database change and appends an array of allowed user IDs. The Realtime server then delivers the change to the user only if the connected user is matched in this array.<p>This one has been a long time coming, and it's one of the reasons why we have maintained our "beta" badge for so long. A few of the team will be here to answer any questions - my cofounder @awalias and @steve-chavez from PostgREST, @inian, @wenbo and @1_over_n<p>[0] Realtime Show HN: <a href="https://news.ycombinator.com/item?id=22114560" rel="nofollow">https://news.ycombinator.com/item?id=22114560</a>)<p>[1] SQL function: <a href="https://github.com/supabase/realtime/blob/master/server/priv/repo/migrations/20211124070109_enable_realtime_apply_rls_function_postgrest_9_compatibility.exs" rel="nofollow">https://github.com/supabase/realtime/blob/master/server/priv...</a>