3 ms·
Ask HN: How to sync up the experience for large number of users of a web app?
What's a reliable method for making sure that if 1,000 people are all using my web app to participate in the same thing that what they're seeing is always within a second or two of being totally in sync?
I'm looking for kind of a generic solution, but in the simplest scenario: Over the course of a minute I want to show 3 different pictures and when each one changes it should update on every user's screen at the same time regardless of when they loaded the page.
- dxjones 18y agoFirst, you need each instance of your running web app to be synchronized to the same clock, so they can make events occur at the same time. Second, it would probably be best to upload your images from your server to your 1,000 clients before they need to be displayed. This can be done asynchronously, so you server doesn't struggle to get it all done within a few seconds. Third, your web app clients could handshake they received the images, ... or you could just allow enough time to pass so you are confident they all have the images, ... and then they could all flip their displays at a pre-arranged time. Voila. Synchronized image display.
- edw519 18y ago"First, you need each instance of your running web app to be synchronized to the same clock, so they can make events occur at the same time." Or you could just preload the delta between your clock and their clock onto the client and trigger a javascript event so the client does all the work.
- dxjones 18y agoYes, "preloading the delta between the server clock and the client clock" is what I had in mind when I wrote "synchronized to the same clock". That is, synchronized to the server clock.
- twohey 18y agoThis is one outline, but you need to be aware of edge cases because networks partition and clocks drift. You should make sure that you gracefully handle (or at the minimum aware of) the following cases: 1. Some of your clients lose network connectivity, so when they see an image they respond, but their network drops out. 2. Some clients have incredible clock skew. This can happen due to any number of very improbable events like time zone changes or faulty motherboards, but it does happen. Distributed synchronization really depends on what kind of experience you are trying to provide. For example, if you are showing slides and you want everyone to be "synchronized" you could have all clients poll for the next image, load it in the background, and then notify you that they have it. Once all clients have notified you they have the image you would then push out a command to the clients to display this next image. Your synchronization needs may be totally different if you are trying to provide a different experience. There are some rather fundamental limits on distributed coordination. For a starting point, see "Time, Clocks, and the Ordering of Events in a Distributed System" by Leslie Lamport available at http://research.microsoft.com/en-us/um/people/lamport/pubs/time-clocks.pdf http://research.microsoft.com/en-us/um/people/lamport/pubs/t...
- rabidsnail 18y agoDifferential Synchronization: http://www.youtube.com/watch?v=S2Hp_1jqpY8 http://www.youtube.com/watch?v=S2Hp_1jqpY8
- rmc00 18y agoYou may want to take a look at comet and long polling. With this method, you can eliminate reliance on a clock (and all the associated headaches). Using comet/long polling, you can sort of mimic pushing the new pictures to clients. This could be ideal because it wouldn't matter when users load the page. Your mileage may vary, however, depending on your specific requirements.
- mindhacker 18y agoComet (http://en.wikipedia.org/wiki/Comet_(programming) http://en.wikipedia.org/wiki/Comet_(programming)) can be used to make sure that all your clients are in sync. rupy (http://code.google.com/p/rupy/ http://code.google.com/p/rupy/) might be a good place to start.