Is manual cleanup of unused interest groups required in Photon Realtime, or can custom properties replace them?
0 reputation · 24 Feb 2024, 11:33 UTC
0 reputation · 24 Feb 2024, 11:33 UTC
Goal: Determine whether developers should manually clean up unused interest groups in Photon Realtime or rely on custom properties for event filtering.
Constraints: Interest group subscriptions are not persisted across reconnections, the server supports a maximum of 255 groups per client, and there is no built‑in mechanism to automatically remove unused groups.
Uncertainty: The documentation does not prescribe a lifecycle strategy, and community discussions are split between manual management and using custom properties for similar filtering.
Questions: Should interest group cleanup be performed explicitly after each room session, or is it acceptable to let groups linger until the 255 limit is reached? Does using custom properties eliminate the need for interest groups altogether?
32775 reputation · 24 Feb 2024, 21:05 UTC
You do not need to clean up interest groups at room boundaries — subscriptions are discarded automatically when the client leaves the room, and they are not persisted across reconnects. You do need explicit cleanup while the client stays inside a long-lived room and stops caring about a group, both to stop receiving unwanted traffic and to stay under the per-client group cap. Custom properties are a different mechanism (shared state, not a routing channel), so they cannot fully replace interest groups for targeted, high-frequency event filtering.
Confirmed behavior (well-established Photon Realtime semantics):
OpChangeGroups; publishing targets a group number.Recommendation (the part docs don't prescribe): treat subscription lifecycle as mirror of your logical contexts. Subscribe when entering a context (a zone, a team, a match phase), unsubscribe via OpChangeGroups(null, groupsToRemove) when leaving it, and treat room leave as a full reset — no cleanup call needed there.
Only if your room sessions are short or your group count is small and bounded. The cost of lingering is not server-side — it is bandwidth: the client keeps receiving every event published to groups it no longer cares about, and on Photon Cloud, message volume is what you pay for. In a long-lived room with dynamic contexts (e.g., a player moving between map zones), failing to unsubscribe means steadily rising receive traffic and eventually a failed OpChangeGroups call at the cap. So: cleanup is cheap, do it on context change, not on room exit.
No — they solve a different problem. Room and actor custom properties are key-value state that the server broadcasts on change. They are not a publish/subscribe routing channel. You can emulate filtering with them only indirectly: publish all events to everyone, attach a property (e.g., team ID), and have clients locally discard irrelevant events. That works when filtering is coarse and event volume is low, but every client pays the receive cost for every event, which inflates message counts and client processing.
The pattern that tends to work well in practice is a hybrid:
Exact API surface and limits vary between client SDK versions and Cloud vs. self-hosted Server configurations, so verify rather than trust the numbers:
OpChangeGroups returns an error to confirm the effective cap under your plan.One caveat worth flagging: the 255 figure and the exact OpChangeGroups overloads should be checked against the SDK version you ship with — treat them as configuration-dependent, not universal constants.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.