Build the future of communications.
Start building for free

Introducing Sync – Real-time State Synchronization API

Twilio Sync – the easy way to synchronize application state

Today we’re excited to introduce Sync, a purpose-built API for easily synchronizing state across devices and between users. State synchronization is a critical part of every application, but it’s a complex problem to solve in real-time, at scale. With Twilio Sync, developers can now spend their time building features for customers instead of building state synchronization infrastructure or customizing general purpose backend products. Sync is designed to work either as a completely stand alone state management system or in tandem with Twilio Programmable Voice, Video, IP Messaging or other Twilio products to provide context rich, real-time communications.

Every app today is a real-time app

When streaming music, listeners expect to transition between their phone and laptop seamlessly and control what they are listening to from either device. When co-editing a shared document, collaborators expect to see updates as they’re made. When requesting a ride, riders expect to be able to track the driver’s progress in real-time. Millisecond-level state synchronization is the fabric for building cross-platform apps, interactive experiences, and embedded communications within apps.

Managing state at scale

The typical approaches to state management involves either operating your own state sync infrastructure at scale or wrestling with general purpose pub/sub products. Twilio Sync solves this by providing a single source of state in the cloud that synchronizes published state changes to subscribed devices. Sync is the real-time engine behind Twilio IP Messaging that handles millions of messages around the world. Now, this infrastructure is available to every developer.

State Synchronization API

The Sync API provides three different types of mutable JSON objects for different state management use cases.

Document – A single JSON object, up to 16kb in size that is best suited for pub/sub or other use cases when history synchronization is not required.

Create a document with the JavaScript SDK:

client.document("myDocument").then(function(doc) {
      doc.set({ number: 12345 });
});

 

List – An ordered list of individual JSON objects well suited for more advanced use cases, like synchronizing location data with the ability to replay old location states. Access individual items through a system generated index.

Subscribe to the list with the JavaScript SDK and receive new items and updates to existing list items:

client.list("myList").then(function(list) {
      list.on("itemAdded", function(item) {
        console.log("List item added!", item);
      });
});

 

Map – An unordered collection of developer specified keys and values. Maps are useful when clients are interested in updates to individual keys, like managing presence where the key is the username and the value is their current availability status.

Create a map via the REST API so it’s ready and available for clients ahead of time.

$client = new TwilioRestClient("your_account_sid",
                                     "your_auth_token");
$sync = $client->preview->sync;
$service = $sync->services->getContext("your_sync_service_sid");

$mymap = $service->syncMaps->create(['uniqueName' => "myFirstMap"]);

Availability

Sync is available today as a developer preview. Initially, we’ll be onboarding a limited number of developers to the docs, REST API, and JavaScript SDK (with mobile SDKs coming soon).

To learn more and request early access, visit twilio.com/sync. We can’t wait to see what you build.

 

Authors
Sign up and start building
Not ready yet? Talk to an expert.