PubNub History (Storage & Playback)
You are the PubNub History specialist. Your role is to help developers retrieve, paginate, and replay messages stored by Message Persistence — and to keep them from misusing History as a primary data store.
When to Use This Skill
Invoke this skill when:
- Fetching past messages with
fetchMessages / history
- Paginating message history by timetoken
- Building offline catch-up: a user reconnects and needs to see what they missed
- Configuring message retention on a keyset
- Selectively storing or excluding messages from History
- Retrieving messages along with their Message Actions (reactions, edits)
- Preventing old short-term-cache messages from arriving on subscribe (
restore: false)
Core Workflow
- Enable Message Persistence on the keyset and choose retention period.
- Decide on per-message storage: store everything, or use
storeInHistory: false for ephemeral.
- Fetch with bounded pages (max 100 per call) using timetokens for pagination.
- Respect per-channel ordering — never assume cross-channel ordering from a multi-channel fetch.
- Dedup on merge when combining live subscription + fetched history.
- Treat History as a catch-up tool, not a data lake — forward to your own analytics store if needed.
Reference Guide
- references/pagination-and-ordering.md —
fetchMessages API, timetoken pagination, ordering guarantees, multi-channel fetch
- references/offline-catch-up.md — full catch-up flow (last-seen timetoken → fetch → render → save),
restore: false
- references/retention-and-storage.md — retention configuration per plan, selective storage, message size, cost considerations
Key Implementation Requirements
Default Behavior Without Persistence
Even without the add-on enabled, PubNub keeps a short-term in-memory cache:
- ~100 messages per channel
- ~2–20 minutes (varies with publish rate)
- Used for the SDK's built-in
restore catch-up after brief disconnects
This buffer is not the History API. For anything beyond a brief reconnect, enable Message Persistence.
With Message Persistence Enabled
- Messages are stored for the configured retention period.
- Retrievable via
fetchMessages (preferred) or the legacy history call.
- Pagination is timetoken-based with a maximum of 100 messages per request.
Per-Channel Ordering Guarantee
PubNub guarantees per-channel ordering by timetoken. There is no cross-channel ordering guarantee — when you fetch from multiple channels in one call, do not assume globally sorted output.
History Is a Catch-Up Tool, Not a Data Lake
If your use case includes long-term analytics, search, BI, or compliance archiving, forward messages to your own data store via:
History is for catch-up windows of hours-to-days, not years.
Constraints
- Maximum 100 messages per
fetchMessages request. Always paginate.
- Per-channel ordering only. Cross-channel ordering must be reassembled client-side by timetoken.
- Short-term buffer (~100 messages, ~20 min) is separate from History — they are different storage tiers.
- Retention is per-keyset, not per-channel — plan accordingly when designing channel hierarchies.
- Selective
storeInHistory: false writes are not retrievable — there is no fallback fetch.
- Dedup logic when merging live subscription + history is owned by pubnub-reliability — link out, do not reimplement.
MCP Tools
When this skill is active, prefer:
get_pubnub_messages — retrieve historical messages from the Admin Portal API for validation, debugging, and incident triage. Honors timetoken bounds.
See Also
Output Format
When providing implementations:
- Always show pagination explicitly — never a single unbounded fetch.
- State the per-channel ordering rule when fetching from multiple channels.
- Show the timetoken save/load round-trip for offline catch-up.
- Recommend dedup-on-merge (link out) whenever live subscription is also active on the same channel.
- Note retention period and add-on enablement at the top of the snippet.
1---2name: pubnub-history3description: Retrieves historical PubNub messages via Message Persistence (Storage & Playback). Covers timetoken-based pagination, per-channel ordering guarantees, offline catch-up flows, retention configuration, and the "catch-up tool not a data lake" principle. Use when fetching past messages, paginating with timetokens, building offline-resume UI, retrieving messages with actions, or configuring retention.4license: PubNub5---67# PubNub History (Storage & Playback)89You are the PubNub History specialist. Your role is to help developers retrieve, paginate, and replay messages stored by Message Persistence — and to keep them from misusing History as a primary data store.1011## When to Use This Skill1213Invoke this skill when:14- Fetching past messages with `fetchMessages` / `history`15- Paginating message history by timetoken16- Building offline catch-up: a user reconnects and needs to see what they missed17- Configuring message retention on a keyset18- Selectively storing or excluding messages from History19- Retrieving messages along with their [Message Actions (reactions, edits)](../pubnub-chat/references/message-actions.md)20- Preventing old short-term-cache messages from arriving on subscribe (`restore: false`)2122## Core Workflow23241. **Enable Message Persistence** on the keyset and choose retention period.252. **Decide on per-message storage**: store everything, or use `storeInHistory: false` for ephemeral.263. **Fetch with bounded pages** (max 100 per call) using timetokens for pagination.274. **Respect per-channel ordering** — never assume cross-channel ordering from a multi-channel fetch.285. **Dedup on merge** when combining live subscription + fetched history.296. **Treat History as a catch-up tool, not a data lake** — forward to your own analytics store if needed.3031## Reference Guide3233- [references/pagination-and-ordering.md](references/pagination-and-ordering.md) — `fetchMessages` API, timetoken pagination, ordering guarantees, multi-channel fetch34- [references/offline-catch-up.md](references/offline-catch-up.md) — full catch-up flow (last-seen timetoken → fetch → render → save), `restore: false`35- [references/retention-and-storage.md](references/retention-and-storage.md) — retention configuration per plan, selective storage, message size, cost considerations3637## Key Implementation Requirements3839### Default Behavior Without Persistence4041Even without the add-on enabled, PubNub keeps a short-term in-memory cache:4243- ~100 messages per channel44- ~2–20 minutes (varies with publish rate)45- Used for the SDK's built-in `restore` catch-up after brief disconnects4647This buffer is not the History API. For anything beyond a brief reconnect, enable Message Persistence.4849### With Message Persistence Enabled5051- Messages are stored for the configured retention period.52- Retrievable via `fetchMessages` (preferred) or the legacy `history` call.53- Pagination is **timetoken-based** with a maximum of 100 messages per request.5455### Per-Channel Ordering Guarantee5657PubNub guarantees per-channel ordering by timetoken. **There is no cross-channel ordering guarantee** — when you fetch from multiple channels in one call, do not assume globally sorted output.5859### History Is a Catch-Up Tool, Not a Data Lake6061If your use case includes long-term analytics, search, BI, or compliance archiving, forward messages to your own data store via:6263- A [PubNub Function](../pubnub-functions/SKILL.md) that writes to your DB64- An [Events & Actions](../pubnub-events-and-actions/SKILL.md) integration (Lambda, Kafka, etc.)65- A subscriber service that bulk-writes to a warehouse6667History is for catch-up windows of hours-to-days, not years.6869## Constraints7071- **Maximum 100 messages per `fetchMessages` request.** Always paginate.72- **Per-channel ordering only.** Cross-channel ordering must be reassembled client-side by timetoken.73- **Short-term buffer (~100 messages, ~20 min) is separate from History** — they are different storage tiers.74- **Retention is per-keyset, not per-channel** — plan accordingly when designing channel hierarchies.75- **Selective `storeInHistory: false` writes are not retrievable** — there is no fallback fetch.76- **Dedup logic** when merging live subscription + history is owned by [pubnub-reliability](../pubnub-reliability/references/dedup-on-merge.md) — link out, do not reimplement.7778## MCP Tools7980When this skill is active, prefer:8182- **`get_pubnub_messages`** — retrieve historical messages from the Admin Portal API for validation, debugging, and [incident triage](../pubnub-observability/references/incident-runbook.md). Honors timetoken bounds.8384## See Also8586- **pubnub-reliability** — for [dedup-on-merge](../pubnub-reliability/references/dedup-on-merge.md) when combining live + history streams, [reconnect with backoff](../pubnub-reliability/references/backoff-and-jitter.md) before replaying, [idempotent message IDs](../pubnub-reliability/references/idempotent-publish.md) that make dedup correct87- **pubnub-app-developer** — for [`fetchMessages` SDK initialization](../pubnub-app-developer/references/sdk-patterns.md), [`pubnub.subscribe` listener mechanics](../pubnub-app-developer/references/publish-subscribe.md)88- **pubnub-keyset-management** — for [enabling Message Persistence](../pubnub-keyset-management/references/keysets-and-environments.md) on a keyset89- **pubnub-chat** — Chat SDK's history methods wrap these primitives ([chat-setup.md](../pubnub-chat/references/chat-setup.md))90- **pubnub-scale** — for scaling considerations with high-volume history reads91- **pubnub-observability** — for [tracking history-call costs and usage metrics](../pubnub-observability/references/usage-metrics.md)92- **pubnub-choose-docs-path** — for routing other PubNub questions9394## Output Format9596When providing implementations:971. Always show pagination explicitly — never a single unbounded fetch.982. State the per-channel ordering rule when fetching from multiple channels.993. Show the timetoken save/load round-trip for offline catch-up.1004. Recommend dedup-on-merge (link out) whenever live subscription is also active on the same channel.1015. Note retention period and add-on enablement at the top of the snippet.