108

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?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Jatin
  • 13,582
  • 14
  • 46
  • 73
  • 2
    http://docs.meteor.com/#sevenprinciples – mplungjan Apr 18 '12 at 17:12
  • 8
    This is a constructive, factual question. Any valid answers would HAVE to be "supported by facts, references, or specific expertise." Apparently casperOne has misunderstood the question or the criteria for designating a question as not constructive. – Charlie Flowers Dec 07 '12 at 13:50
  • 3
    But this question will likely solicit "extended discussion" and doesn't have an "answer" answer. – durron597 Dec 07 '12 at 14:13
  • 9
    @durron597 I think you are saying that the answer to the question is very large (correct me if I've misunderstood). I can see that, but that is not the same as being "not constructive". The definition of "not constructive" in the boilerplate summary that appears below makes it clear that the "not constructive" tag is for non-objective questions. This question is 100% objective. Meteor works the way it works. If multiple opinions start showing up here, then all but one of them are going to be wrong. – Charlie Flowers Dec 10 '12 at 03:03
  • @mplungjan I find none of these answers satisfying because none of them adequately addresses the Meteor principle of "Data on the Wire. Meteor doesn't send HTML over the network. The server sends data and lets the client render it." the first principle of the 7 principles. – Alexander Mills Dec 23 '14 at 05:58
  • Here is a good explanation of the Meteor: https://www.youtube.com/watch?v=FsnZB6yRimI – Ejaz Karim Oct 30 '16 at 10:02

3 Answers3

81

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:

  • It provides templating that updates automatically when your data models do. This is normally done using Backbone.js, Ember.js, Knockout.js, or another tool.

  • The client/server messaging is done via websockets using something like socks.js or socket.io.

  • 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.

There may be other neat pieces to that you can find on the Meteor site, or on GitHub.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
xer0x
  • 11,912
  • 5
  • 30
  • 28
28

Disclaimer: This answer describes Meteor, JavaScript client library for Meteor Server. It was originally added due to ambiguity in the question, and may serve the purpose of clarifying similar ambiguities faced by the visitors searching for similar answers, but unsure about the difference.

To read about Meteor JavaScript framework, please see this answer by xer0x.

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).

Community
  • 1
  • 1
Tadeck
  • 117,059
  • 25
  • 140
  • 191
  • For the lazy, COMET is a programming technique, there is a comprehensive discussion here: http://www.infoq.com/news/2008/12/websockets-vs-comet-ajax – snez Apr 20 '12 at 12:40
  • 1
    There is Meteor and there is Meteor Server. I have a feeling the original question was about the former and this answer was about the latter? http://www.meteor.com/ and http://meteorserver.org/ – ile Apr 23 '12 at 00:38
  • 2
    No, the Meteor.com stuff is an advanced form of Comet. Specifically it uses long polling, you can watch it in the chrome dev tools. – wmil Apr 23 '12 at 20:54
  • 1
    @ile: Yes, there is JavaScript framework called _Meteor_ (https://github.com/meteor/meteor) and there is _Meteor.js_, a client part for Meteor Server (http://meteorserver.org/client-docs/). I believe this is the question is too ambiguous to tell which one of these OP had really in mind. – Tadeck Apr 23 '12 at 22:00
  • I wonder why it's built on Comet and not WebSockets.. – Olivier Refalo Apr 24 '12 at 02:10
  • @OlivierRefalo: Comet does not need to have additional support in browsers, Web Sockets need it. Comet can be used in most modern browsers, Web Sockets are less reliable (http://en.wikipedia.org/wiki/WebSocket#Browser_support), and they have security holes. To sum up: you do not need some extra technology to use Comet. – Tadeck Apr 24 '12 at 02:38
  • 5
    @ile Actually, I was interested in meteor.com . I actually didn't know about meteorserver.org before your comment. – Jatin Apr 24 '12 at 20:45
  • 2
    The meteor.js framework is NOT the meteor http server. Despite the poor naming choice of the folks who made the framework. See http://www.meteor.com for more. – xer0x Apr 26 '12 at 16:36
  • @xer0x: Please see [my comment](http://stackoverflow.com/questions/10214385/how-does-meteor-js-work/10214585#comment13237980_10214585). This should be quite clear after you read it. – Tadeck Apr 26 '12 at 16:45
  • @Jatin, yes, that's what I thought. I could have worded my comment a lot better. (I also didn't know about the Meteor Server until I accidentally stumbled upon it.) – ile May 09 '12 at 04:30
  • 1
    yes I downvoted the answer because of this confusion. – seinecle Jun 04 '12 at 10:01
  • Now that it's clear which `meteor` the OP meant, might you consider deleting this answer? SO will award you a "[Disciplined](http://stackoverflow.com/badges)" badge for deleting the answer. – Dan Dascalescu May 12 '13 at 05:47
  • @Tadeck" Now that it's clear which meteor the OP meant, can you please consider deleting this answer? – Dan Dascalescu Feb 27 '14 at 10:19
  • @DanDascalescu: Thanks for your proposal, but no. The reason is that other users may be confused too, and my answer pretty clearly states, that it is something different than other answers. Yet, I think many users will be having the same question and will be confused at the beginning - having that kind of answer could make them think what they are really looking for. Cannot think about any reason to remove that. Think about usefulness for other visitors. In these terms, this answer still seems to be useful, the same way search engine suggest different meanings/spellings. Don't you think? – Tadeck Feb 27 '14 at 13:43
  • @Tadeck I just arrived here and I'm sorry but your answer confuses this page. Granted that the question title was ambiguous, but surely its better to make an edit to the title to disambiguate it (which I just submitted), than to add to the ambiguity. You could also create a new question, referring to Meteor Server and paste in your answer there. – Julian Mann Sep 19 '14 at 13:52
  • 1
    @JulianMann: Added further explanations to disclaimer. Hopefully this is now satisfactory. – Tadeck Sep 21 '14 at 14:27
25

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.

snez
  • 2,154
  • 21
  • 18