MongoDB at Gilt (MongoDB Seattle 2012)

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
sullis
September 14, 2012

MongoDB at Gilt (MongoDB Seattle 2012)

MongoDB at Gilt Groupe
MongoDB Seattle 2012
September 14, 2012

sullis

September 14, 2012

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

77 slides
  1. • software engineer • ~18 months at Gilt • work

    in Gilt’s Portland office • back office applications About me
  2. @

  3. Why MongoDB? • Ease of use • Horizontal scaling •

    High availability • Automatic failover
  4. • user data in Postgres • legacy Rails app expects

    to find user data in Postgres • we want Gilt’s customer facing application code to retrieve user data from MongoDB Challenges
  5. • keep user data in both MongoDB and Postgres •

    replicate table changes from Postgres to MongoDB Solution
  6. Use case #2: feature configuration Goal manage the release of

    new features on gilt.com How feature configuration persisted in MongoDB
  7. Rolling out a new feature 1. deploy new application code

    to production 2. enable feature for Gilt Tech employees 3. ... then enable for all Gilt employees 4. ... then enable for a subset of users 5. gradually ramp up to 100% of users
  8. MongoDB Java driver • main class: com.mongodb.Mongo • Mongo object

    maintains a pool of connections • Latest version: 2.9.1
  9. MongoDB Java driver connection pool tuning MongoOptions opts = new

    MongoOptions(); // example values opts.connectionsPerHost = 50; opts.threadsAllowedToBlockForConnectionMultiplier = 5;
  10. Morphia • object-document mapper for Java • built on top

    of mongo-java-driver • map fields using Java annotations
  11. // Morphia example import com.google.code.morphia.annotations.*; @Entity(value="features", noClassnameStored = true) public

    class Feature { @Id ObjectId featureId; @Property("feature_key") @Indexed(unique=true) String featureKey; @Property("release_to_percentage") int releaseToPercentage; }
  12. trait MongoWriteConcern { def withSession[T](f: => T)(implicit mongoDb: MongoDB) {

    mongoDb.requestStart() mongoDb.requestEnsureConnection() try { f } finally { mongoDb.requestDone() } } }
  13. Best practices Use caution when creating new indexes “creating a

    new index on a production mongo server can basically cause it to stop working while it builds the index” (source: Gilt production incident report)
  14. http://docs.mongodb.org/manual/administration/indexes/#index-building-replica-sets Minimizing impact of building a new index • remove

    one secondary from replica set • create/rebuild index on this instance • rejoin replica set • repeat on all remaining secondaries • run rs.stepDown() on primary member
  15. Best practices use short names for fields to avoid wasted

    space http://christophermaier.name/blog/2011/05/22/MongoDB-key-names { city: “Portland”, state: “Oregon”, country: “US” } { ci: “Portland”, st: “Oregon”, co: “US” } vs
  16. Best practices use caution when choosing a shard key “It

    is generally not a good idea to use the default ObjectId as the shard key” source: http://stackoverflow.com/questions/9164356/sharding-by-objectid-is-it-the-right-way
  17. Future • standardized read preferences • tag aware sharding MongoDB

    2.2 Mongo Java driver 2.9.x • enhanced read preference support (see: com.mongodb.ReadPreference)
  18. Gilt tech talks • Apache Camel and MongoDB @ Gilt

    http://bit.ly/OYO37K • Deploying new features @ Gilt http://slidesha.re/OoCYfd • Voldemort @ Gilt http://bit.ly/b9Qhib

More Decks by sullis

Other Decks in Technology