Skip to main content
Presence tracks ephemeral per-client state with a TTL. Entries expire automatically when a client stops sending heartbeats. Ideal for “who’s online”, cursor positions, and typing indicators.

Usage without schema

Usage with schema

API

PresenceEntry

TTL behavior

Entries expire when now > expiresAtMs. Call heartbeat() periodically to keep the entry alive. online() always filters out expired entries before returning. The server runs a background GC task every few seconds that removes expired entries and broadcasts tombstone deltas to all connected clients — so peers see removals in near-real-time without waiting for the next heartbeat.

Server restart behavior

Presence is ephemeral by design — entries are stored in sled but the TTL clock is wall-time based. When the server restarts:
  • All presence entries that were already expired remain expired.
  • Entries that were still live will appear missing for connected clients until clients re-heartbeat.
  • Clients receive a fresh empty state on reconnect, then repopulate as they send heartbeats.
This is expected behavior. To handle it gracefully, send a heartbeat() immediately after the WebSocket connects (or reconnects):
There is no server-side “grace period” after restart. If your use case requires durable presence (e.g., last-seen timestamps), use a LwwRegister instead — it persists across restarts.