Suggestions

close search
Speed up your development
Create a Fast Track

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

Server Rotation and Session Migration

Best practices for handling Video API server rotations and having clients automatically reconnect when they occur.

Modern cloud auto-scaling makes it necessary to establish a minimum rotation time for services. Sessions lasting more than 8 hours might be disconnected, as they may reside in services that are scaling out or scaling in.

Monitoring server rotation in sessions

You can register a callback URL for session events to be sent to your callback URL. When a group of Video API servers for one of your sessions is scheduled to be rotated, a sessionNotification event is sent to your registered callback endpoint. See the Session Monitoring documentation.

If clients remain connected to a session when set of servers shut down because of server rotation, a sessionDestroyed event is set to your callback URL. The reason property of the sessionDestroyed event is set to "serverRotation". And each connected client is disconnected from the session and receives a sessionDestroyed event.

Clients using version 2.30.0 or later of the Video API client SDKs can automatically stay connected to a session when servers for the session rotate. See the next section, Automatic session migration.

For clients using older versions of the client SDKs, there are steps you can take in response to a sessionNotification event to keep clients connected. (See Responding to server rotation session notification events.)

Automatic session migration

The session migration feature seamlessly transfers all participants in a session to a new server during server rotation. This feature ensures session continuity with minimal disruption to participants.

Note: Session migration is a beta feature.

Session migration is available in version 2.30.0 or later of the client SDKs. See the next section, Enabling session migration in clients.

The benefits of enabling session migration include improved reliability, reduced reconnection times, and uninterrupted user experience during planned server transitions. Note only live sessions are migrated. Ongoing recordings may be interrupted during migration and will need to be restarted manually — see Responding to server rotation session notification events.

Enabling session migration in clients

When you initialize a session in the Video API client SDKs, you can set an option to have a client remain connected to the session during server rotation.

By default, the session migration option is set to false. Be sure to set it to true to enable session migration in each client.

Web client SDK (OpenTok.js)

When you call the OT.initSession() pass in an options object with the sessionMigration property set to true:

const session = OT.initSession(
  '12345', // your application ID
  '1_MX40NzIwMzJ-clg1fn5-', // the session ID
  {
    sessionMigration: true,
  },
);

Android client SDK

Pass true into the setSessionMigration() method of the Session.Builder object you use to create a Session object:

mSession = new Session.Builder(this, apiKey, sessionId)
  .setSessionMigration(true)
  // other options
  .build();

iOS client SDK

Set the sessionMigration property of an OTSessionSettings object to YES:

OTSessionSettings *settings = [[OTSessionSettings alloc] init];
settings.sessionMigration = YES;

Use this OTsessionSettings object when calling the [OTSession initWithApiKey:sessionId:delegate:settings:] method.

Windows client SDK

Set the SetSessionMigration property of a Session.Builder object to true:

session = new Session.Builder(context, apiKey, sessionId){ SetSessionMigration = true }.Build();

Linux and macOS client SDKs

Call the otc_session_settings_set_session_migration() method, passing in OTC_TRUE as the second parameter:

otc_session_settings_set_session_migration(settings, OTC_TRUE);

Then pass the otc_session_settings struct as the settings parmeter in the call to the otc_session_new_with_settings() method.

React Native client SDK

Set the sessionMigration property of the options prop of the OTSession component to true:

  <OTSession
    options={{
      sessionMigration: true,
      // other options
    }}
  />

Responding to server rotation session notification events

If there are archives or broadcasts in progress for the original session, you can start new archives or broadcasts for the new session. In the case of broadcasts, you will need to send the new broadcast URL to clients consuming the broadcast.

If clients in the session cannot use version 2.30.0 or later to enable session migration, you will need to take steps to reconnect them after server rotation. When the servers for the session are rotated (one hour after the session notification event is sent), clients connected to the session that do not have session migration enabled will be forced to disconnect from the session. When your application server receives a server rotation session notification callback, it can take action to reconnect these clients to a new session:

  1. Create a new Video API session using the Video API REST API or a Video API server SDK.

  2. Send the session ID for the new session to the clients connected to the session. You may want to use the Video REST API or a Video API server SDK to send the signal to the connected clients. See this documentation.

  3. The clients should immediately disconnect from the original session and reconnect to the new session.

For a more seamless transition between sessions and to minimize any potential reconnection time, clients can remain connected to the initial session and switch the video display before disconnecting from the initial session (upon connecting to the new session).

FAQs

What is Video API server rotation? How frequently are Video API servers updated?

Software cloud scalability requires a continuous ability to rotate servers. Vonage maintains an 8-hour window to avoid excessive rotation of long-lived sessions. Rotations can happen daily.

There are a few main reasons for a media server to be rotated. The main reasons are maintenance, software updates, security patching, infrastructure servicing and elastic autoscaling:

Can I use the same session ID to reconnect once a session is disconnected due to server rotation?

Clients using version 2.30.0 or later of the Video API client SDKs can automatically stay connected to a session during server rotation. See Automatic session migration.

If all clients cannot use version 2.30.0 or later of the client SDKs, you can have them reconnect to a sesssion. Using a new session ID is recommended to assure that the new session is directed to a new server instance. If the session is disconnected due to server rotation, all clients will be disconnected. If the same session ID is used, the reconnection will be moved to a new server after the session is terminated, following the sessionDestroyed event.