Persistent Replay & Presence

Goal: Understand ephemeral vs persistent state.

Replay: messages that survive restarts

In-memory replay buffers are lost on restart. Redis replay persists them.

import { createReplay } from 'svelte-adapter-uws-extensions/redis';

export const replay = createReplay(redis, { maxPerTopic: 200 });

When a client reconnects, it sends its last sequence number. The replay buffer sends all messages since then - even across restarts.

Presence: who’s online across instances

In-memory presence only sees local connections. Redis presence aggregates across all instances.

import { createPresence } from 'svelte-adapter-uws-extensions/redis';

export const presence = createPresence(redis, {
  heartbeatInterval: 15000,
  expireAfter: 30000
});

Handles multi-tab dedup - the same user in three tabs shows up once.

When to use which

DataEphemeral (in-memory)Persistent (Redis)
Cursor positionsYesOnly if multi-instance
Who’s onlineYesYes, for accurate cross-instance counts
Message replayAcceptable for devRequired for production with restarts
Rate limitsYesYes, for distributed enforcement

Was this page helpful?