Upgrade to Pro — share decks privately, control downloads, hide ads and more …

mongoDB at Intercom

mongoDB at Intercom

These slides are from a talk I gave at the first meeting of the Dublin mongoDB users group.

ciaranlee

May 23, 2012
Tweet

More Decks by ciaranlee

Other Decks in Technology

Transcript

  1. • What we do • Why we started using mongoDB

    • Learnings • Problems • Hosting Overview Wednesday 23 May 12
  2. <script> var intercomSettings = { app_id:"tx2p130c", email:"[email protected]" }; </script> <script

    src="https://api.intercom.io/api/ js/library.js"</script> Wednesday 23 May 12
  3. • Rails • MySQL • MongoDB • Redis • Memcached

    • Solr Technology Stack Wednesday 23 May 12
  4. • Open beta • Installed on thousands of apps •

    Tracking millions of end users Current status Wednesday 23 May 12
  5. MySQL • Initially used for all data • We had

    a built high traffic apps with it before (@exceptional) Wednesday 23 May 12
  6. class User < ActiveRecord::Base serialize :custom_data end user.custom_data = {

    :plan => "Small", :team_mates => 4, :revenue => 312, } Wednesday 23 May 12
  7. • Reading and writing worked fine • Sorting or filtering

    was a disaster Results Wednesday 23 May 12
  8. Why MongoDB? • Handles arbitrary document structure • Flexible querying

    • Can use an ActiveRecord compatible ORM (mongomapper) • Available as a heroku addon Wednesday 23 May 12
  9. The Mongo way • Different way of thinking to relational

    DB • Often denormalised • Desired read scenarios influence design Wednesday 23 May 12
  10. Tagging • Relational way is users + tags + join

    table • Mongo way is a tag_ids array in the user record Wednesday 23 May 12
  11. db.users.update( { app_id: 6, 'custom_data.apps': { $gte: 5 } },

    { $addToSet: { tag_ids:1234 } } ); Wednesday 23 May 12
  12. db.users.update( { app_id: 6, 'custom_data.apps': { $gte: 5 } },

    { $addToSet: { tag_ids:1234 } } ); Wednesday 23 May 12
  13. db.users.update( { app_id: 6, 'custom_data.apps': { $gte: 5 } },

    { $addToSet: { tag_ids:1234 } } ); Wednesday 23 May 12
  14. Problem #1 • Querying users has gotten slower • Users

    collection is 1/4 the size of activities • Activity stream growing too fast • Knocks the users collection out of RAM Wednesday 23 May 12
  15. Solution • Move the activity stream over to a separate

    database • We can use the more powerful database for complex user queries • sorting + filtering should be quicker Wednesday 23 May 12
  16. Problem #2 • Can’t index every custom data attribute •

    Intend to experiment with app specific user collections (+ index all custom data attrs on that app’s collection) Wednesday 23 May 12
  17. Slowness • Always seems to involve disk access • Slow

    performance of simple queries after big addToSet operations (> 200k users) Wednesday 23 May 12
  18. Hosting • MongoHQ • Replica set - heroku addon •

    ec2 cluster • Dedicated hardware with SSDs • Amazing service Wednesday 23 May 12