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

MongoDB at Gilt (MongoDB Austin 2013)

sullis
February 15, 2013

MongoDB at Gilt (MongoDB Austin 2013)

MongoDB at Gilt
February 15, 2013
Austin Texas

sullis

February 15, 2013
Tweet

More Decks by sullis

Other Decks in Technology

Transcript

  1. • software engineer • ~2 years 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 wanted Gilt’s customer facing applications to retrieve user data from MongoDB Challenges
  5. • keep user data in both MongoDB and Postgres •

    replicate from MongoDB to Postgres Solution
  6. Replication service • listens for RabbitMQ messages ‣ UserCreated message

    ‣ UserUpdated message • retrieve data using REST API • write data to Postgres using JDBC
  7. Use case #2: feature configuration Goal manage the release of

    new features on gilt.com How feature configuration persisted in MongoDB
  8. 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
  9. MongoDB Java driver • main class: com.mongodb.Mongo • Mongo object

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

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

    of mongo-java-driver • map fields using Java annotations
  12. // 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; }
  13. Casbah • Scala toolkit for MongoDB • built on top

    of the mongo-java-driver • current version: 2.5.0
  14. trait MongoWriteConcern { def withSession[T](f: => T)(implicit mongoDb: MongoDB) {

    mongoDb.requestStart() mongoDb.requestEnsureConnection() try { f } finally { mongoDb.requestDone() } } }
  15. 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)
  16. 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
  17. 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
  18. 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
  19. Future • shipping addresses • discounts • SKU’s and brands

    More Gilt data in MongoDB • tag aware sharding Upgrade to MongoDB 2.2
  20. 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