I'm building a chat app with Supabase Realtime and using chat-based channel subscriptions: one channel per chat room (chat:{chat_id}) for messages/typing, plus one user channel (chat:{user_id}) for things like invites/refresh and one presence channel. So total channels per connection = 1 + 1 + (number of chats). Users can be logged in on multiple devices (web, mobile, desktop) at the same time. On our plan we have a limit of 100 channels per connection. For users with 100+ chats we can't subscribe to every chat at once.
What we're considering
Subscribe only to a subset of chats (e.g. top N by recency) and evict when we need to add another.
Keeping backend state of each user's subscribed chat IDs (client reports on subscribe/unsubscribe) and using that to decide: send to room channel chat:{chat_id} when we think the client has that room subscribed, and to user channel chat:{user_id} when we think they don't, so we avoid duplicate delivery and only send where the client is listening. Alternatively (or as a fallback), sending message events to each participant's user channel so users never miss messages for chats they're not subscribed to; room channels only for optional stuff (e.g. typing).
What we'd like to know
Is there a recommended or documented pattern from Supabase for this (prioritising channels, eviction, or falling back to user-scoped channels when you hit the limit)?
Any best practices for "user has more channels than the limit" and for multi-device (e.g. different devices having different subscribed sets, overwriting when each device reports its list)?
If you've built something similar (chat or other multi-room realtime), how did you handle the per-connection channel cap and/or backend subscription state?
We're on Supabase Pro. Thanks in advance.
The user is building a chat app with Supabase Realtime and faces a challenge with the 100-channel-per-connection limit. They are exploring strategies to manage subscriptions for users with over 100 chats, including prioritizing channels and using user-scoped channels. They seek guidance on best practices for handling channel limits and multi-device scenarios.