I came across Meteor and while it seems exciting, I want to know how it works. I mean conventional web applications work like this:
You have scripts on server which take data from database and add that dynamically to web-pages and the user-submitted data gets added to databases through some other scrips.
But how do these things work in Meteor? How are different parts of Meteor related to each other?
Meteor is a framework that elegantly updates HTML in realtime.
The beauty of Meteor is that you only need to create the templates and the data models. The rest of the usual boilerplate code is hidden away. You don’t need to write all the sync-ing code.
The key pieces of Meteor could be built yourself using these pieces:
The client side connection to MongoDB is really cool. It replicates the MongoDB-server driver into the client. Unfortunately, last I checked, they were still working on securing this database connection.
The latency compensation is simply updating the client-side model first, then sending the update to the server-server.
As mentioned on the Meteor Server’s documentation, Meteor is an implementation of Comet. Comet in turn is a counterpart of AJAX.
In case of AJAX, you usually make a request when the client sees a need to do that. To pull updates from the server, you will need to call the server eg. every 5 seconds.
In case of Comet, the update from the server comes faster, because the connection is persistent. The connection is established by client, as in AJAX, but the server does not respond until it has some update or it reaches execution limit (scripts on the server may have execution limits).
In case of Meteor you just get constant stream of data that needs some specific server-side code (like Meteor Server) and appropriate code on the client (in this case it looks like it is Meteor class).
All the magic with the live data updating is happening because of the dependency tracking system. An explanation of how it works can be found at the Tracker section of the documentation.