Consider this code snippet subscribing to a Supabase table:
const subscription = supabase
.from('messages')
.on('INSERT', payload => {
console.log('New message:', payload.new);
})
.subscribe()Which event will cause the callback to run?
const subscription = supabase .from('messages') .on('INSERT', payload => { console.log('New message:', payload.new); }) .subscribe()
Think about what 'INSERT' means in database terms.
The 'INSERT' event triggers when a new row is added to the table. The callback receives the new row data.
You have a subscription object from Supabase. How do you properly stop listening to database changes?
const subscription = supabase .from('orders') .on('UPDATE', payload => { console.log('Order updated:', payload.new); }) .subscribe() // What code unsubscribes correctly?
Check Supabase docs for the method to remove subscriptions.
Supabase uses removeSubscription(subscription) to stop listening and clean up the subscription.
You expect thousands of database changes per minute. Which architecture helps handle this efficiently?
Think about distributing workload to avoid bottlenecks.
Multiple clients subscribing to filtered subsets distribute load and improve scalability.
You want to make sure users only get real-time updates for data they are allowed to see. Which feature helps enforce this?
Think about database-level access control.
Row Level Security (RLS) policies restrict which rows a user can access, including in real-time subscriptions.
Your app loses internet connection and then reconnects. How should you handle the subscription to avoid missing events?
Consider how to avoid missing events during disconnects.
Resubscribing and fetching missed data ensures no events are lost during connection drops.
