Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect meteor to an existing backend?

Tags:

mongodb

meteor

I recently discovered Meteor, and I really love the simplicity that it brings to programming new apps. My question is: how do you connect it to an existing back-end? We have a substantial amount of existing Clojure code, also running with MongoDB. What I would like to do is use Meteor to build the front-end of my app. I guess I could connect my Meteor app directly to the MongoDB instance of the back-end, but this does not seem like a good practice... or is it?

Another option I imagined was to access the DB from either the webapp or the Clojure code and create a separate way of communication between the two with a queue mechanism, or sockets. Any hint or pointer to relevant documentation would be helpful!

like image 565
seb Avatar asked Nov 10 '13 18:11

seb


2 Answers

Take a look at Meteor's environment variable settings. By setting these variables you can easily define an external MongoDB instance. In particular it would be

$export MONGO_URL="mongodb://yourmongodbserver/your-db"

There is a screencast of eventedmind.com for this specific topic https://eventedmind.com/feed/sg3ejYnmhxpBNoWan which is quite resourceful.

like image 162
Michael Birsak Avatar answered Nov 10 '22 01:11

Michael Birsak


Regarding the "how" to point them to the same, @Michael's answer is spot on; just point your Meteor web servers at the same MongoDB.

Regarding whether or not you should, that depends on your situation. Having everything run off the same DB certainly simplifies things.

Having separate dbs can potentially reduce the load on your db tier as you could selectively choose which writes/updates to replicate between the clojure and Meteor dbs.

One issue with either method is speed of notification of changes. Currently, Meteor servers poll the DB every 10 secs to recognize changes. Happily, once the oplog branch gets merged into master, it will give a large speed improvement in how quickly external changes made in the DB (as opposed to directly through a Meteor server) are reflected in the Meteor clients. The oplog support will enable Meteor servers to emulate a replica-set instance, tailing the oplog which will mean practically instant notification of db changes.

Using a queue as a middle-ware layer introduces complexity and adds another point of failure. It also increases latency of notification. These issues can be mitigated, though, and there may be other pieces of your infrastructure in the future that would benefit from such a middle-ware queue. For example, other interested systems could register with the queue to receive notification of changes without querying or needing to know about your db. You can also scale your MongoDB instances independently and tune the queue to determine what "eventually" means in the "eventually consistent" guarantee.

I think the questions to ask are:

  • how much overlap is there between the clojure dataset and the Meteor dataset
  • how quickly do you need changes to be reflected between the two
  • will a middle-ware queue be useful in other circumstances as you grow

Regarding possible queue technologies to look into, I've heard very good things about RabbitMQ. The Oct. 2013 talk at the Clojure NYC meetup included a description of switching to RabbitMQ from Amazon SQS due to latency issues with SQS and anecdotally RabbitMQ has been rock-solid for them.

like image 26
alanning Avatar answered Nov 10 '22 01:11

alanning