Client resource management
Own views explicitly, bound local work and recover from resource pressure.
Service quotas and local SDK limits are independent. A client can exhaust a local resource even when the service has capacity.
Own only the views you need
Topic handles are lightweight addresses. Headless publishing and callback subscriptions do not retain implicit message history. Acquire a view lease before subscribing if initial replay or snapshots should populate the view.
import type { Realtime } from '@folkwaysio/realtime';
export async function showRoom(client: Realtime) {
const room = client.topic('rooms/42');
const messages = room.messages.open();
const typing = room.values('typing').open();
const sub = room.subscribe({ from: { last: 20 } });
try {
await sub.ready;
console.log(messages.getSnapshot(), typing.getSnapshot());
} finally {
await sub.unsubscribe();
messages.dispose();
typing.dispose();
}
}Subscription readiness is not replay completion. Reactive bindings acquire ownership with view.subscribe(listener) and release it through the returned cleanup. Views on the same topic share active data. Opening a view alone does not request replay. Active message views have a one-tick remount grace period before final disposal releases history.
Local budgets
| Resource | Default | Configuration |
|---|---|---|
| Pending publishes | 1,000 / 8 MiB | pendingPublishes.maxCount / maxBytes |
| Inbound work per topic | 4,096 / 4 MiB | inbound.perTopicCount / perTopicBytes |
| Inbound work across client | 65,536 / 32 MiB | inbound.maxCount / maxBytes |
| Current state | 65,536 / 32 MiB | inbound.stateCount / stateBytes |
| Iterator buffer per iterator | 256 / 2 MiB | Fixed |
| Aggregate iterator buffers | 8,192 / 8 MiB | Fixed |
| Active view leases | 1,024 | Fixed |
| Settled display history | 100 entries / 2 MiB per topic; 8 MiB across client | Fixed |
| Inactive in-memory cursors | 1,024 | Fixed |
| Optional cache | 100 messages per topic; 2 MiB resident budget; 256 topics | cache.messagesPerTopic / maxBytes |
These are estimated retained-byte limits, not JavaScript heap guarantees. Pending optimistic messages have separate accounting and are not silently evicted to admit new sends. Settled display history may be evicted. Committed state and temporary snapshot assembly each have a ceiling; during atomic replacement both may coexist temporarily (up to twice the state budget in aggregate). The last complete state stays visible until the replacement commits. Persistent cache accounting includes encoding overhead and is separately bounded; use one owner per namespace.
import { Folkways } from '@folkwaysio/realtime';
export function createClient(token: string) {
return new Folkways.Realtime({
url: 'https://realtime.folkways.net',
token,
pendingPublishes: { maxCount: 500, maxBytes: 4 * 1024 * 1024 },
inbound: { perTopicCount: 2048, stateBytes: 16 * 1024 * 1024 },
});
}Recover from overload
Acknowledged publishes reject with QueueFull; signals may be dropped. Reduce publishing pressure and handle ambiguous outcomes using stable idempotency keys. Iterator overflow throws QueueFull for the affected iterator only; aggregate pressure sheds the largest backlog first. Terminal topic errors discard buffered iterator items. Unsubscribe, client close and identity change finish iteration normally. A topic-set member ending does not terminate the set.
A shared cursor tracks callback delivery and enqueueing, not successful asynchronous iterator processing. Save an application-owned checkpoint and resume from it when necessary, subject to retained history. If an incoming current-state snapshot exceeds the budget, adjust the relevant limit or workload before resubscribing. Inactive cursor eviction may require an explicit starting position.
Inspect resource usage
import type { Realtime } from '@folkwaysio/realtime';
export function inspect(client: Realtime) {
const d = client.diagnostics();
console.log(d.activeTopics, d.viewLeases, d.pendingPublishes, d.inboundBytes);
}| Counters | Meaning |
|---|---|
| activeTopics, subscriptions | Active topic and subscription counts |
| kvValues, signalValues, retainedStateBytes | Retained current state |
| inboundCount, inboundBytes | Pending inbound work |
| pendingPublishes, pendingPublishBytes | Pending publications |
| cacheTopics, cacheBytes, inactiveCursors | Cache and cursor usage |
| viewTopics, viewLeases, viewMessages, viewValues, viewMessageBytes | Active view ownership and retained display data |
Diagnostics are local and payload-free; byte estimates are not a heap profiler. Measure actual memory under representative workloads.
See migration, client options and local storage.