# Notification replay

> An operator wants to resend four webhook events and has room for eight deliveries. Three events are order updates and one is a refund. Each event goes to every subscription on its topic. With three order subscriptions and one refund subscription, the replay creates **10 deliveries** (`3 × 3 + 1 × 1`). Move two subscriptions from orders to refunds and the same batch creates **6 deliveries** (`3 × 1 + 1 × 3`). This problem checks the delivery cap before creating any of those pairs.

An operator wants to resend four webhook events and has room for eight deliveries. Three events are order updates and one is a refund. Each event goes to every subscription on its topic. With three order subscriptions and one refund subscription, the replay creates **10 deliveries** (`3 × 3 + 1 × 1`). Move two subscriptions from orders to refunds and the same batch creates **6 deliveries** (`3 × 1 + 1 × 3`). This problem checks the delivery cap before creating any of those pairs.

## Result

> With 100 ranges, summaries approve 16 of 32 replays and cost a mean 43,200 bytes, against 80,000 to fetch both count arrays

## Modules

* [`knotkit/frequency-table`](/modules/frequency-table/): Maintains exact counts, prefix sums, range sums, and rank selection over a fixed integer domain
* [`knotkit/inverted-index`](/modules/inverted-index/): Indexes records by exact keys and scans sorted record IDs for one key or the union of several, using packed posting lists

## Figures

* Four events and four subscriptions. Delivery cap is 8.
* Most subscriptions on orders gives 10 deliveries, rejected after counting.
* Most subscriptions on refunds gives 6 deliveries, approved from topic summaries.

Hover or focus a chart for exact values. Drawn by [`demo.ts`](https://github.com/jkomyno/knotkit/blob/main/problems/notification-replay/demo.ts) at build time, from the fixtures the benchmark uses; it reproduces the README figure.

## Reproduce

```bash
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:notification-replay
```

[`problems/notification-replay/README.md`](https://github.com/jkomyno/knotkit/blob/main/problems/notification-replay/README.md) states the fixture, the seed, and the result table.
