Supabase Realtime
Supabase Realtime lets your app receive instant updates when data changes — perfect for chat apps, live feeds, and collaborative features.What is Realtime?
Instead of constantly polling for new data, Realtime pushes changes to your app instantly:Prerequisites
- Supabase connected
- A table to subscribe to
- RLS policies configured
Enabling Realtime
In Supabase Dashboard
- Go to Database → Tables
- Select your table
- Click “Realtime” toggle to enable
Basic Subscription
Ask Nativeline:Subscription Code Pattern
Event Types
| Event | When It Fires |
|---|---|
insert | New row added |
update | Existing row modified |
delete | Row removed |
* (all) | Any change |
Use Cases
Live Chat
Activity Feed
Collaborative Lists
Live Notifications
Filtering Subscriptions
By Column Value
Only listen for messages in a specific chat:By User
Only listen for the current user’s notifications:Handling Changes
Insert (New Data)
Update (Modified Data)
Delete (Removed Data)
Unsubscribing
Always clean up subscriptions when leaving a screen:Realtime + RLS
Realtime respects Row Level Security:- Users only receive events for rows they can SELECT
- Your existing RLS policies apply automatically
- No additional security configuration needed
Performance Considerations
Subscribe to specific tables
Subscribe to specific tables
Don’t subscribe to tables you don’t need. Each subscription uses resources.
Filter when possible
Filter when possible
Use column filters to reduce events received. Don’t subscribe to all messages if you only need one chat room.
Unsubscribe when done
Unsubscribe when done
Always unsubscribe when leaving screens. Orphaned subscriptions waste resources.
Handle reconnection
Handle reconnection
Supabase handles reconnection automatically, but you may want to refresh data after a reconnection.
Troubleshooting
Not receiving updates
Not receiving updates
- Is Realtime enabled on the table?
- Are RLS policies allowing SELECT?
- Is the subscription active?
- Check Supabase dashboard logs
Receiving all events (not filtered)
Receiving all events (not filtered)
- Check filter syntax
- Verify column name is correct
- Ensure filter value matches data type
Duplicate events
Duplicate events
- May have multiple subscriptions
- Unsubscribe when view disappears
- Use unique channel names
Connection drops
Connection drops
Supabase auto-reconnects, but after prolonged disconnection:
- Refresh data when connection restores
- Show connection status to user
Example: Building Live Chat
Create messages table
- id (uuid)
- chat_id (uuid)
- user_id (uuid)
- content (text)
- created_at (timestamp)