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

MongoNYC 2012: Using MongoDB to Build Art.sy

mongodb
May 25, 2012
2k

MongoNYC 2012: Using MongoDB to Build Art.sy

MongoNYC 2012: Using MongoDB to Build Art.sy, Daniel Doubrovkine, Art.sy. Art.sy started as a prototype built on top of a relational database, only to be quickly replaced with MongoDB. In this talk we'll walk along a year-long timeline of using MongoDB as our project matured and the number of developers and users grew significantly. We'll focus on failures, success stories, design patterns and lessons learned.

mongodb

May 25, 2012
Tweet

Transcript

  1. » N-Gram Search https://github.com/artsy/mongoid_fulltext class Artist include Mongoid::Document include Mongoid::FullTextSearch

    field :first_name field :last_name def name [first_name, last_name].join(' ') end fulltext_search_in :name end
  2. ~ 50 of 850 genes MongoDB: A Sparse Hash {

    Contemporary : 100, Computer Art : 20, Plays With Scale: 80, Humor : 70, Nostalgia : 0, Hairy or Fluffy : 0 }
  3. MongoDB: Inheritance in the Database { _type : SoloArtist, birthday

    : 1929, deathday : 1972 } { _type : ArtCollective founded : 1929 }
  4. MongoDB: Cartesian Product { id : BSON::ObjectId(…) color : red,

    medium : works-on-paper, size : small, price : [0, 12, 48], }
  5. MongoDB: from LSH to K-Most Similar Graph { artwork_id :

    BSON::ObjectId(…) neighbors : [[ BSON::ObjectId(…), score ], … ] } http://www.mit.edu/~andoni/LSH/ http://www.cs.princeton.edu/cass/papers/www11.pdf
  6. class User include Mongoid::Document field :account_created, default: false has_many :authentications

    def account_created? account_created || authentications.any? end end task :migrate do User.where({ :account_created.exists => false }).each do |user| user.update_attributes!({ account_created: user.account_created? }) end end
  7. REST API as little online processing as possible as much

    offline parallel processing as possible iPad CMS Web
  8. » Mongoid Cached JSON https://github.com/dblock/mongoid-cached-json REST API class Widget include

    Mongoid::CachedJson field :name has_many :gadgets json_fields \ :name => { }, :gadgets => { :type => :reference, :properties => :public } end
  9. testing models and APIs will save your life class User

    include Mongoid::Document end class Admin < User end class Representative include Mongoid::Document belongs_to :user, inverse_of: :representative belongs_to :admin , inverse_of: nil end
  10. • mongoid-history • carrierwave-mongoid • mongoid_fulltext • mongoid_slug • delayed_job_mongoid

    • mongoid_collection_snapshot • delayed_job_shallow_mongoid • mongoid-cached-json
  11. » $15 - $49 per developer / month » 149$

    / month for a Small Replica Set » $1345 / month for a Large Replica Set -------- ~ 25K$ / year on database hosting