Sync - I don't get it

aaron_cl
aaron_cl ✭✭✭
edited July 20 in Sync

I've read through the documentation and forgive me if I'm missing something, but isn't sync basically just a glorified redis cache?

What are the situations where you're using sync?

Best Answer

  • pnash
    pnash mod
    Accepted Answer

    Chat does use Sync under the hood, but it is again abstracted away. In the case of Chat, you now deal with Channels, Users and Members over Sync Documents, Lists or Maps. So, when you update a channel's attributes you don't need to dig into find the underlying Sync service, you listen for the updated event on the Channel object. To use Chat you do not need to know that it is backed by Sync, I just thought I'd bring it up as an important use-case for Sync itself.

Answers

  • What's up @aaron_cl! I see Sync as an abstraction over websockets that allows you to more easily handle synchronising state between one or more client applications. The back-end implementation is irrelevant, whether it is Redis or otherwise. That you can create documents, lists and maps make it easier to reason about the data you are using and subscribe to the right data for each client.

    The biggest thing that Sync powers is Programmable Chat/Conversations. It's also been used to implement co-browsing and I got a good deal of the way to implementing a live blog with it.

    Have you worked with Sync yourself? There are some good examples of how to use it on the blog recently, including:

  • aaron_cl
    aaron_cl ✭✭✭

    Thank you @pnash. This gives me a better understanding of how it's intended to be used, and I can see it being useful in certain cases.

    It seems like this is intended to be a tool beyond the scope of typical twilio products, and a general purpose front-end state synchronization solution.

    further questions

    I assume webchat is using sync for state management as well?

    When I update attributes on a chat via a serverless function like client.chat.services(sSid).channels(chSid).update({attributes}), webchat is using Sync to monitor and update those changes. Is this correct?

    If attributes property on a chat is a general purpose sync "bucket", and I can update that using update() method, what are some twilio service specific cases where you find the need to access the Sync service directly rather than just adding attributes to the associated chat resource?

Sign In or Register to comment.