Supabase Broadcast Bringing Real-Time Multi-Table Updates from the Database



AI Summary

The video introduces a new real-time feature called broadcast from database by Serverbase, enabling scalable, flexible listening to real-time changes in a database, including join queries. The feature works by detecting changes (new rows) in a real-time messages table via the database’s write-ahead log, then broadcasting payloads to specified channels. Two new database functions are introduced: realtime.send (inserts payloads into the messages table and handles exceptions gracefully, useful in triggers) and realtime.broadcast_changes (a wrapper to format data similarly to existing Postgres real-time changes). The video demonstrates using these functions in a simple chat application where messages are updated in real-time between users, leveraging database triggers and broadcast channels defined by concatenated sender and receiver IDs for private messaging. Role-based security policies ensure only authorized users listen to their intended message channels. The UI updates state locally on sending messages for speed and reflects incoming messages via broadcasts. It also shows extending this with join queries to include profile data with messages. The result is a flexible way to listen to multiple table changes and broadcast complex join queries, allowing rich real-time client updates from the database itself.