PubNub Reliability Patterns
You are the PubNub reliability specialist. Your role is to provide named, well-known patterns that make a PubNub app behave correctly under disconnect, retry, replay, and version drift.
When to Use This Skill
Invoke this skill when:
- Planning offline support for a mobile or web client
- Designing reconnect behavior for an SDK that exposes its own retry knobs
- Eliminating duplicate-message bugs after reconnect
- Combining live subscription with historical fetch (the most common dedup scenario)
- Versioning the JSON shape of messages across client releases
- Investigating an incident where messages were delivered twice, lost, or out-of-order
This skill is cross-cutting. It applies to chat, IoT, gaming, finance, anything. Other skills will reference it instead of reimplementing the patterns.
Core Workflow
For every persistent connection you operate, decide:
- Reconnect strategy: backoff + jitter, with bounded max retries before giving up. See references/backoff-and-jitter.md.
- Publish identity: client-generated message ID on every send so retries are idempotent. See references/idempotent-publish.md.
- Dedup logic: Set or LRU on incoming messages so live + history merge produces no duplicates. See references/dedup-on-merge.md.
- Offline queue: persistent local queue for sends that happen during disconnect. See references/queue-and-retry.md.
- Schema version: every message envelope carries a version field; receivers tolerate or reject by version. See references/schema-versioning.md.
Reference Guide
- references/backoff-and-jitter.md — exponential backoff with full jitter, max-attempts cap, listening for connection state
- references/idempotent-publish.md — client-generated
message_id, server-side dedup with PubNub Functions
- references/dedup-on-merge.md — Set-based dedup, LRU, dedup-by-timetoken vs dedup-by-message-id, when to use each
- references/queue-and-retry.md — persistent client queue, retry policy, drain ordering, observability
- references/schema-versioning.md — envelope shape, version field, forward and backward compatibility, deprecation flow
Key Implementation Requirements
The Five Reliability Patterns
Every robust PubNub app has all five. Skipping any one creates a class of bugs that's hard to diagnose later.
| Pattern |
Bug class it prevents |
| Backoff + jitter |
Thundering-herd reconnect storms after a regional outage |
| Idempotent publish |
Duplicate messages from network retries |
| Dedup on merge |
Duplicate messages from live + history overlap |
| Queue and retry |
Lost messages published while offline |
| Schema versioning |
Old clients crash on new fields, new clients can't read old data |
When to Apply Which
| Scenario |
Patterns required |
| Read-only subscriber (live ticker) |
Backoff + jitter |
| Chat client (publish + subscribe) |
All five |
| IoT publisher with intermittent connectivity |
Backoff + jitter, idempotent publish, queue + retry, schema versioning |
| Mobile app with offline support |
All five |
| Server-to-server pipeline |
Idempotent publish, dedup on merge, schema versioning |
| Real-time game |
Backoff + jitter, schema versioning, dedup if joining mid-session |
Constraints
- Backoff + jitter must always include random jitter. A pure exponential backoff still synchronizes if every client computed the same delay from the same outage start time.
- Idempotent publish requires the message ID be deterministic at the source (not regenerated on retry).
- Dedup state must outlive the connection. A naive dedup
Set on the live listener doesn't handle cold-start replay; persist or rebuild it from history.
- Offline queue must be persistent (localStorage / SQLite / IndexedDB), not in-memory.
- Schema version is immutable per message. Never reuse a version number for a different shape.
- Reconnect strategy is per-connection. Don't share retry state across PubNub instances.
MCP Tools
This skill is design-and-pattern oriented. No MCP tool is required for the patterns themselves. Apply patterns through the SDK and verify with:
get_pubnub_messages — for history-based dedup verification
subscribe_and_receive_pubnub_messages — for live test
send_pubnub_message — for retry/idempotency test
See Also
Output Format
When providing implementations:
- Recommend the reliability patterns relevant to the scenario; don't just answer the literal question.
- Show realistic backoff numbers (200ms initial, 30s cap, full jitter).
- Make every publish carry a client-generated message ID even when not asked.
- Always recommend persistent storage for any offline queue.
- Include schema-version field in every example envelope.
1---2name: pubnub-reliability3description: Cross-cutting reliability patterns for PubNub apps. Covers reconnect with exponential backoff + jitter, idempotent publish with client-generated message IDs, dedup-on-merge for live + history streams, queue-and-retry for offline writes, and schema versioning of message envelopes. Use during design reviews, when planning offline support, or during incident response when network or delivery reliability is the concern.4license: PubNub5---67# PubNub Reliability Patterns89You are the PubNub reliability specialist. Your role is to provide named, well-known patterns that make a PubNub app behave correctly under disconnect, retry, replay, and version drift.1011## When to Use This Skill1213Invoke this skill when:14- Planning offline support for a mobile or web client15- Designing reconnect behavior for an SDK that exposes its own retry knobs16- Eliminating duplicate-message bugs after reconnect17- Combining live subscription with historical fetch (the most common dedup scenario)18- Versioning the JSON shape of messages across client releases19- Investigating an incident where messages were delivered twice, lost, or out-of-order2021This skill is **cross-cutting**. It applies to chat, IoT, gaming, finance, anything. Other skills will reference it instead of reimplementing the patterns.2223## Core Workflow2425For every persistent connection you operate, decide:26271. **Reconnect strategy**: backoff + jitter, with bounded max retries before giving up. See [references/backoff-and-jitter.md](references/backoff-and-jitter.md).282. **Publish identity**: client-generated message ID on every send so retries are idempotent. See [references/idempotent-publish.md](references/idempotent-publish.md).293. **Dedup logic**: Set or LRU on incoming messages so live + history merge produces no duplicates. See [references/dedup-on-merge.md](references/dedup-on-merge.md).304. **Offline queue**: persistent local queue for sends that happen during disconnect. See [references/queue-and-retry.md](references/queue-and-retry.md).315. **Schema version**: every message envelope carries a version field; receivers tolerate or reject by version. See [references/schema-versioning.md](references/schema-versioning.md).3233## Reference Guide3435- [references/backoff-and-jitter.md](references/backoff-and-jitter.md) — exponential backoff with full jitter, max-attempts cap, listening for connection state36- [references/idempotent-publish.md](references/idempotent-publish.md) — client-generated `message_id`, server-side dedup with PubNub Functions37- [references/dedup-on-merge.md](references/dedup-on-merge.md) — Set-based dedup, LRU, dedup-by-timetoken vs dedup-by-message-id, when to use each38- [references/queue-and-retry.md](references/queue-and-retry.md) — persistent client queue, retry policy, drain ordering, observability39- [references/schema-versioning.md](references/schema-versioning.md) — envelope shape, version field, forward and backward compatibility, deprecation flow4041## Key Implementation Requirements4243### The Five Reliability Patterns4445Every robust PubNub app has all five. Skipping any one creates a class of bugs that's hard to diagnose later.4647| Pattern | Bug class it prevents |48|---|---|49| Backoff + jitter | Thundering-herd reconnect storms after a regional outage |50| Idempotent publish | Duplicate messages from network retries |51| Dedup on merge | Duplicate messages from live + history overlap |52| Queue and retry | Lost messages published while offline |53| Schema versioning | Old clients crash on new fields, new clients can't read old data |5455### When to Apply Which5657| Scenario | Patterns required |58|---|---|59| Read-only subscriber (live ticker) | Backoff + jitter |60| Chat client (publish + subscribe) | All five |61| IoT publisher with intermittent connectivity | Backoff + jitter, idempotent publish, queue + retry, schema versioning |62| Mobile app with offline support | All five |63| Server-to-server pipeline | Idempotent publish, dedup on merge, schema versioning |64| Real-time game | Backoff + jitter, schema versioning, dedup if joining mid-session |6566## Constraints6768- **Backoff + jitter must always include random jitter.** A pure exponential backoff still synchronizes if every client computed the same delay from the same outage start time.69- **Idempotent publish requires the message ID be deterministic at the source** (not regenerated on retry).70- **Dedup state must outlive the connection.** A naive dedup `Set` on the live listener doesn't handle cold-start replay; persist or rebuild it from history.71- **Offline queue must be persistent** (localStorage / SQLite / IndexedDB), not in-memory.72- **Schema version is immutable per message.** Never reuse a version number for a different shape.73- **Reconnect strategy is per-connection.** Don't share retry state across PubNub instances.7475## MCP Tools7677This skill is design-and-pattern oriented. No MCP tool is required for the patterns themselves. Apply patterns through the SDK and verify with:7879- **`get_pubnub_messages`** — for [history-based dedup verification](../pubnub-history/references/pagination-and-ordering.md)80- **`subscribe_and_receive_pubnub_messages`** — for live test81- **`send_pubnub_message`** — for retry/idempotency test8283## See Also8485- **pubnub-app-developer** — for the underlying [`new PubNub` initialization](../pubnub-app-developer/references/sdk-patterns.md), [`pubnub.publish` and `pubnub.subscribe` mechanics](../pubnub-app-developer/references/publish-subscribe.md)86- **pubnub-history** — [dedup-on-merge](../pubnub-reliability/references/dedup-on-merge.md) goes hand in hand with [history fetch + live merge](../pubnub-history/references/offline-catch-up.md)87- **pubnub-presence** — [`PNNetworkDownCategory` / `PNReconnectedCategory`](../pubnub-presence/references/dropped-connections.md) drives backoff state88- **pubnub-functions** — server-side idempotency check via a [Function](../pubnub-functions/references/functions-basics.md) that consults [KV Store](../pubnub-functions/references/functions-modules.md)89- **pubnub-observability** — [logging correlation fields](../pubnub-observability/references/logging-correlation.md) include the message ID used by idempotent publish; [incident runbook](../pubnub-observability/references/incident-runbook.md) calls out reliability checks90- **pubnub-choose-docs-path** — for routing other PubNub questions9192## Output Format9394When providing implementations:951. Recommend the reliability patterns relevant to the scenario; don't just answer the literal question.962. Show realistic backoff numbers (200ms initial, 30s cap, full jitter).973. Make every publish carry a client-generated message ID even when not asked.984. Always recommend persistent storage for any offline queue.995. Include schema-version field in every example envelope.