Dedup
createDedup() is an in-process key-set with fixed-window TTL. Use to drop duplicates of the same logical request inside a window - webhook delivery, idempotency keys, retry storms.
Setup
// src/lib/server/dedup.js
import { createDedup } from 'svelte-adapter-uws/plugins/dedup';
export const seen = createDedup({ ttlMs: 60_000 }); Usage
import { seen } from '$lib/server/dedup';
if (await seen.acquire(requestId)) {
// First time we have seen this id within the window.
await processWebhook(payload);
} else {
// Duplicate - drop silently or return 200 OK to the sender.
} API
| Method | Description |
|---|---|
acquire(key) | true if first time within the window; false for duplicates. |
has(key) | Membership check without acquiring. |
delete(key) | Force-evict a key. |
clear() | Drop all entries. |
Options
| Option | Default | Description |
|---|---|---|
ttlMs | 60000 | Window size in ms. |
maxKeys | 1_000_000 | Capacity cap. Past the cap, oldest entries evict. |
maxIdLength | 256 | Reject acquire(key) / has(key) / delete(key) calls where key.length > maxIdLength synchronously. Pass Infinity to disable. |
The 256-char maxIdLength is a defense-in-depth bound. Pre-cap, a 1 MB wire-supplied key would anchor a 1 MB heap entry until the TTL elapsed. The cap throws synchronously with the actual length, so callers can log the offender.
See also
- Idempotent RPCs -
live.idempotent- the realtime wrapper for idempotent server functions. createIdempotencyStore- Postgres / Redis idempotency store with three-state acquire semantics.
Was this page helpful?