14
Meteor: The Application as One System
From the very beginning the web had one limitation nobody thought about for a long time: the browser always starts the conversation. It sends a request, the server answers, and there the conversation ends. If the server has something new, say a chat message has arrived or someone has changed a document, it cannot tell the browser until the browser asks. So the first «live» pages simply asked every few seconds whether there was anything new. The answer was almost always «no», almost all the traffic went to these empty questions, and the news still arrived late, at the next question.
In March 2006 Alex Russell, the lead of the Dojo library, wrote a blog post giving a name to a set of techniques some developers were already using by then. He called them Comet. The simplest was called long polling: the browser sends a request, the server takes its time answering and keeps the connection open until data appears, answers, and the browser immediately sends the next request. Cleverer was the hidden-frame technique. The page opened a frame that never finished loading, and the server every now and then appended bits of script to it, which the browser executed as soon as it received each one. Both techniques worked, but on the servers of the time every open connection occupied a thread or a process, and a thousand users waiting for news meant a thousand sleeping threads. Three years later Ryan Dahl would run into the same difficulty and put it on his slides when presenting Node. And Russell himself, in 2012, together with Wirfs-Brock, would lead the discussion of the «maximally minimal classes» from the second chapter.
The real solution came in December 2011, when the WebSocket standard was published. The browser opens a connection once, and from then on both it and the server can write to it whenever they like. But browsers did not learn this at once, and proxies and corporate networks kept breaking such connections for a long time, so libraries became popular that tried to open a WebSocket and, if that failed, quietly fell back to long polling. One of them, SockJS, became the foundation of Meteor.
Free, one step away
The rest of the book is free
Leave your email and I will send a link to confirm it. Once you click it, every chapter opens here, on this device, for a year. When a new book comes out I will write to this address; reply “stop” to any email and I will not write again.
Have an INITE account? Sign in and the book opens without an email.
I do not charge for the book. If you would like to support it, you can donate from any chapter.
How your email is stored