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:| Package | Minimum | Maximum |
|---|---|---|
| Free | 24 hours | 24 hours |
| PAYG | 72 hours | 365 days |
| Enterprise | 72 hours | Custom |
Enable persisted storage
To enable persisted storage for a channel:- Sign in to your Ably account
- Select your app
- Go to the Settings tab
- Click Add new rule under Channel Rules
- Enter the channel name or namespace
- Check Persist all messages
- Configure the retention period
- 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
- Sign in to your Ably account
- Select your app
- Go to the Settings tab
- Click Add new rule under Channel Rules
- Enter the channel name or namespace
- Check Persist last message
- 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:| Operation | Message Count |
|---|---|
| Publish | 1 message |
| Publish (with persistence) | 2 messages (1 for publish + 1 for storage) |
| Retrieve from history | 1 message per retrieved message |
| Last message persistence | 1 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:- Go to the Integrations tab in your dashboard
- Click New Integration Rule
- Select Webhook
- Configure your endpoint URL
- Select the channels to integrate
- 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 persistencestate:*- All channels with last message persistencelive:*- All channels with default 2-minute storage
Monitor storage costs
Track your message usage in the dashboard to understand storage costs:- Go to your app in the dashboard
- Click the Usage tab
- View message counts by type
- Monitor persisted vs. ephemeral messages
Next steps
- Learn about message history
- Set up integrations for external storage
- Configure channel rules
- Understand pricing
