Skip to main content
Ably stores all messages for two minutes by default. This can be increased up to a year, or longer, depending on your account package. It is also possible to persist the last message sent to a channel for a year. Ably integrations can also be used to send messages outside of Ably for long-term storage.

Default storage (2 minutes)

The default message storage of two minutes enables clients that briefly disconnect from Ably to automatically retrieve any messages they may have missed. These messages can also be retrieved using the history feature, and this applies to both regular messages and presence messages.

Persist all messages

If you need to retain messages for longer than the default two minutes you can enable persisted history by setting a channel rule. The time that messages will be stored for depends on your account package:
PackageMinimumMaximum
Free24 hours24 hours
PAYG72 hours365 days
Enterprise72 hoursCustom

Enable persisted storage

To enable persisted storage for a channel:
  1. Sign in to your Ably account
  2. Select your app
  3. Go to the Settings tab
  4. Click Add new rule under Channel Rules
  5. Enter the channel name or namespace
  6. Check Persist all messages
  7. Configure the retention period
  8. Click Create channel rule

Query persisted messages

Persist last message only

You can persist just the last message sent to a channel for one year by setting a channel rule. This is useful for state channels where you only need the most recent value.

Enable last message persistence

  1. Sign in to your Ably account
  2. Select your app
  3. Go to the Settings tab
  4. Click Add new rule under Channel Rules
  5. Enter the channel name or namespace
  6. Check Persist last message
  7. Click Create channel rule

Retrieve the last message

Use the rewind channel option to get the last persisted message: Or retrieve it via the history API:

Storage costs

Understand the message costs for storage:
OperationMessage Count
Publish1 message
Publish (with persistence)2 messages (1 for publish + 1 for storage)
Retrieve from history1 message per retrieved message
Last message persistence1 additional message when published

Store messages outside Ably

For long-term storage, complex queries, or compliance requirements, use integrations to send messages to your own systems:

Webhooks

Send messages to your server via HTTP webhooks:
  1. Go to the Integrations tab in your dashboard
  2. Click New Integration Rule
  3. Select Webhook
  4. Configure your endpoint URL
  5. Select the channels to integrate
  6. Click Create

Message queues

Stream messages to message queues:
  • AWS Kinesis: For real-time data streaming
  • AWS SQS: For reliable message queuing
  • Azure Event Hubs: For event streaming
  • Google Cloud Pub/Sub: For asynchronous messaging

Databases

Use serverless functions to store in your database:

Message deletion

Ably does not currently provide an API to delete persisted messages from history. Once messages are stored with persisted history enabled, they remain for the entire configured storage period. If you need to delete specific messages from history, contact support.

Best practices

Choose the right storage option

Use channel namespaces for storage rules

Apply storage rules to channel namespaces instead of individual channels:
  • persisted:* - All channels with full persistence
  • state:* - All channels with last message persistence
  • live:* - All channels with default 2-minute storage

Monitor storage costs

Track your message usage in the dashboard to understand storage costs:
  1. Go to your app in the dashboard
  2. Click the Usage tab
  3. View message counts by type
  4. Monitor persisted vs. ephemeral messages

Next steps

Build docs developers (and LLMs) love