You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Distribute first-level channel keys:** Yorkie servers route channels based on the first-level key. Using the same first-level key (e.g., `app.*`) for all channels concentrates load on a single server, causing performance bottlenecks. Distribute traffic by using varied first-level keys:
967
+
**Query channel information:** Use the [GetChannels API](/docs/web-api#post-yorkiev1adminservicegetchannels) to retrieve presence counts for specific channels and their sub-levels.
Yorkie servers determine which server handles a channel based on a combination of your project and the first-level key of the channel. Using the same first-level key for all channels means all your channels will be managed by the same server, which can lead to performance bottlenecks and uneven load distribution.
973
+
974
+
Design your channel key structure to naturally distribute traffic across different first-level prefixes for optimal performance.
975
+
968
976
```javascript
969
977
// ✅ Good: Distributed first-level keys
970
978
newyorkie.Channel('game-1.room-a');
971
979
newyorkie.Channel('chat-1.thread-1');
980
+
newyorkie.Channel('chat-2.thread-1');
981
+
newyorkie.Channel('notification-1.user-123');
972
982
973
983
// ❌ Bad: Same first-level key
984
+
// All channels share 'app' as first level - avoid this!
974
985
newyorkie.Channel('app.game-1');
986
+
newyorkie.Channel('app.game-2');
975
987
newyorkie.Channel('app.chat-1');
988
+
newyorkie.Channel('app.notification-1');
976
989
```
977
-
978
-
**Query channel information:** Use the [GetChannels API](/docs/web-api#post-yorkiev1adminservicegetchannels) to retrieve presence counts for specific channels and their sub-levels.
Broadcast messages are ephemeral and only delivered to clients currently connected to the channel. Messages are not persisted or stored, so clients that join later will not receive previous messages.
1019
1031
</Alert>
1020
1032
1021
-
#### Tracking Online Presence
1033
+
#### Tracking Online Sessions
1022
1034
1023
-
Channels automatically track the number of connected clients, making it easy to display "users online" counters:
1035
+
Channels automatically track the number of connected clients, making it easy to display "sessions" counters:
The presence count is automatically updated when clients connect or disconnect from the channel.
1048
+
The session count is automatically updated when clients connect or disconnect from the channel.
1049
+
1050
+
<Alertstatus="warning">
1051
+
Sessions are connection-based and managed for scalability. In abnormal cases (app crash, network partition), a client might not detach cleanly, so the server may keep the session counted until it is considered stale and cleaned up. This means the displayed count can be approximate and may lag briefly; avoid using it as a source of truth for critical business logic (billing, authorization, settlements).
0 commit comments