Yes, all of our client libraries automatically handle connection recovery.


When a client connects to Ably, it is assigned a connection ID (a unique public identifier for that client) and a connection secret key (unique private key that is only known to the client). If the connection to Ably is disconnected abruptly due to issues such as changing from Wifi to 3G, or going through a tunnel, the service Ably will continue to keep that connection alive on its servers for 2 minutes whilst waiting for the client to reconnect.  What that means is that any channels the client was subscribed to or present in will remain attached, and any messages published or presence state changes on those channels will be stored and queued for delivery to the client when it reconnects.


Ably client libraries, when disconnected, automatically try and resume the connection and will continue to try if they do not succeed.  If a client has been previously connected, and is attempting to reconnect, it presents the connection ID, connection secret, and serial of the last message received before it was disconnected to Ably.  With this information Ably is able to securely replay all queued messages and presence state events on all the attached channels back to the client, and the realtime service continues without disruption.


Commonly asked questions


  • How many messages will you store whilst a client is disconnected?
    There is no hard limit so we will in almost all circumstances be able to keep all messages for two minutes.
  • What happens if messages cannot be replayed or the connection cannot be recovered?
    If the connection is not able to be recovered, Ably notifies the client and the client will detach the channels and emit an error.  As a developer then, this gives you certainty and predictability you need to build a reliable application.  If a channel is detached by the server, then you will need to decide what action you may take, including potentially retrieving the history of that channel via our history API.