Slide 1

Slide 1 text

February 2013 Sean Sullivan @

Slide 2

Slide 2 text

• software engineer • ~2 years at Gilt • work in Gilt’s Portland office • back office applications About me

Slide 3

Slide 3 text

• Gilt Groupe • Gilt’s technology stack • MongoDB at Gilt • Q&A Agenda

Slide 4

Slide 4 text

Gilt Groupe http://www.gilt.com

Slide 5

Slide 5 text

flash sales

Slide 6

Slide 6 text

Everyday at 12 noon

Slide 7

Slide 7 text

what does Gilt sell?

Slide 8

Slide 8 text

Apparel

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Kids merchandise

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Home furnishings

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Food

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Local deals

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Travel

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Gilt technology stack

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Gilt architecture

Slide 25

Slide 25 text

monolithic application service-oriented architecture 2007 2013

Slide 26

Slide 26 text

2007

Slide 27

Slide 27 text

2013 service A service B service C service D service E legacy web app gilt.com

Slide 28

Slide 28 text

Data storage @ Gilt

Slide 29

Slide 29 text

@

Slide 30

Slide 30 text

Why MongoDB? • Ease of use • Horizontal scaling • High availability • Automatic failover

Slide 31

Slide 31 text

Why MongoDB? • Stability • Support • Drivers

Slide 32

Slide 32 text

• MongoDB 2.0 • sharded and non-sharded data • Solid State Drives • MMS for monitoring

Slide 33

Slide 33 text

Use case #1: user profiles

Slide 34

Slide 34 text

• 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

Slide 35

Slide 35 text

• keep user data in both MongoDB and Postgres • replicate from MongoDB to Postgres Solution

Slide 36

Slide 36 text

Replicating user data user service legacy web app replication service

Slide 37

Slide 37 text

Replication service • listens for RabbitMQ messages ‣ UserCreated message ‣ UserUpdated message • retrieve data using REST API • write data to Postgres using JDBC

Slide 38

Slide 38 text

Use case #2: feature configuration Goal manage the release of new features on gilt.com How feature configuration persisted in MongoDB

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Feature config service Feature configuration gilt.com

Slide 41

Slide 41 text

Use case #3: favorite brands

Slide 42

Slide 42 text

user preference service AJAX Favorite brands

Slide 43

Slide 43 text

Application development

Slide 44

Slide 44 text

mongo-java-driver Morphia Casbah

Slide 45

Slide 45 text

MongoDB Java driver • main class: com.mongodb.Mongo • Mongo object maintains a pool of connections • Latest version: 2.10.1

Slide 46

Slide 46 text

MongoDB Java driver connection pool tuning MongoOptions opts = new MongoOptions(); // example values opts.connectionsPerHost = 50; opts.threadsAllowedToBlockForConnectionMultiplier = 5;

Slide 47

Slide 47 text

com.mongodb.WriteConcern • NORMAL • SAFE • REPLICAS_SAFE • MAJORITY • FSYNC_SAFE • JOURNAL_SAFE

Slide 48

Slide 48 text

Morphia library

Slide 49

Slide 49 text

Morphia • object-document mapper for Java • built on top of mongo-java-driver • map fields using Java annotations

Slide 50

Slide 50 text

// 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; }

Slide 51

Slide 51 text

http://code.google.com/p/morphia/

Slide 52

Slide 52 text

Casbah library

Slide 53

Slide 53 text

Casbah • Scala toolkit for MongoDB • built on top of the mongo-java-driver • current version: 2.5.0

Slide 54

Slide 54 text

Casbah • Scala idioms • Scala collections • fluid query syntax

Slide 55

Slide 55 text

https://twitter.com/max4f/status/230503836958199808

Slide 56

Slide 56 text

Gilt Scala code

Slide 57

Slide 57 text

trait MongoWriteConcern { def withSession[T](f: => T)(implicit mongoDb: MongoDB) { mongoDb.requestStart() mongoDb.requestEnsureConnection() try { f } finally { mongoDb.requestDone() } } }

Slide 58

Slide 58 text

Best Practices

Slide 59

Slide 59 text

Best practices Connection tuning explicitly configure Mongo Java Driver connection pool size

Slide 60

Slide 60 text

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)

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

Best practices use explain() during development db.collection.find(query).explain()

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

Future • shipping addresses • discounts • SKU’s and brands More Gilt data in MongoDB • tag aware sharding Upgrade to MongoDB 2.2

Slide 66

Slide 66 text

Gilt Groupe is hiring! http://techjobs.gilt.com

Slide 67

Slide 67 text

Questions?

Slide 68

Slide 68 text

[email protected] @tinyrobots

Slide 69

Slide 69 text

The end

Slide 70

Slide 70 text

Bonus slides

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

https://twitter.com/stripe/status/298858032421535744

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content