Ably stores all messages for two minutes by default. This can be increased to 24 hours, or 72 hours 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.
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.
The following diagram illustrates the default persistence of messages:
If you need to retain messages for longer than the default two minutes you can enable persisted history by setting a channel rule. When persisted history is enabled for a channel any messages will be stored on disk for 24 or 72 hours depending on your account package.
Messages can be retrieved using the history feature. This is illustrated in the following diagram:
Note that every message that is persisted to, or retrieved from, disk counts as an extra message towards your monthly quota. For example, with persistence enabled a published message counts as two messages for your monthly quota. If the message is then retrieved another message will be deducted.
Messages persisted for a year can only be retrieved using the rewind channel option. They cannot be retrieved using the history feature.
The following diagram illustrates persisting the last message sent on a channel:
Integrations provide the ability to store your messages outside of Ably, for example in your own database or data warehouse.
Set up an integration rule to send messages to your own systems using webhooks or serverless functions. Integration rules can additionally filter which messages sent to a channel should trigger these events.