MongoDB at Dog on a Horse

30
Dog on a Horse Mobile Apps A MongoDB Ready Partner

Transcript of MongoDB at Dog on a Horse

Page 1: MongoDB at Dog on a Horse

Dog on a HorseMobile Apps

A MongoDB Ready Partner

Page 2: MongoDB at Dog on a Horse

Woody’s Great Grandfather

Page 3: MongoDB at Dog on a Horse

Digital Trading Card Platform with Topps

Three apps that run on the same systemso far…

HUDDLE

BUNT

KICK

MLB

NFL

BPL

Collectible Card Games

Page 4: MongoDB at Dog on a Horse

Yes, That Topps

Page 5: MongoDB at Dog on a Horse

The New Trading Card

Live stats and game info

Online trading

Card sales info

Page 6: MongoDB at Dog on a Horse

Brief History of BUNT• 2012: Introduced product on MySQL

• Revenue model fine-tuned

• Thought of new features and scaling considerations

• Migrate to MongoDB for MLB 2013 opening day

• Learn MongoDB

• Re-design the schema

• Write & Run migration scripts

• Total: 4-5 months, 1-2 people

Page 7: MongoDB at Dog on a Horse

• Product Demo

• System Overview

• Specific example of why MongoDB

• One case where another database technology is used with MongoDB

• Scalability issue and resolution

Page 8: MongoDB at Dog on a Horse

Product Demo

Page 9: MongoDB at Dog on a Horse

System Overview

Page 10: MongoDB at Dog on a Horse

Server Technologies• MongoDB

• MySQL

• Redis

• Python

• AWS

• External data feed

Page 11: MongoDB at Dog on a Horse

MongoDB Basic Structure

Page 12: MongoDB at Dog on a Horse

Simple View of Server Architecture

Page 13: MongoDB at Dog on a Horse

Big Piece 1: Processing Live Data• Live data is received and stored into MySQL• A heartbeat picks up the event and stores player stats into

MongoDB• It then pulls from MongoDB and updates leaderboard data in

Redis

Page 14: MongoDB at Dog on a Horse

Big Piece 2: Formatting Leaderboards for Users• API servers combine fan data from MongoDB with points data

from Redis• The result is a richly-detailed set of leaderboards

Page 15: MongoDB at Dog on a Horse

All other processes• All other processes are handled by the API servers and MongoDB

• Sign in, Trading, Commenting, Content Management, Purchases, Playing Cards

• Storage is used for fan and player photos as well as other simple files

Page 16: MongoDB at Dog on a Horse

Big Piece 1Specific reason we

chose MongoDBProcessing Live Game Data in Realtime

Page 17: MongoDB at Dog on a Horse

Realtime Live Game Updates

• Game play requires up-to-the-minute stats from live events for user scoring

• These data are stored in JSON format for the app

• The JSON data has to be updated frequently with stats and player points

• Support multiple live games for multiple apps on the same platform

Page 18: MongoDB at Dog on a Horse

Old Way: Processing Live Game Data with MySQL

Page 19: MongoDB at Dog on a Horse

New Way: With MongoDB, we can simply update the JSON data in the player’s

document db.players.update( { _id: ObjectId(“52be0717978ca03fc1984069"), ‘games.g':'2013-e.39141 }, { $set:{ 'games.$.b': "1-for-2: Ground out, Walk, Home run" }, $inc:{ 'points': 36 } })

Page 20: MongoDB at Dog on a Horse

In general, the system with MongoDB is much simpler, faster, more

scalable

Page 21: MongoDB at Dog on a Horse

Where we use Redis with MongoDB

Leaderboards

Page 22: MongoDB at Dog on a Horse

Building User Leaderboards

• Leaderboards updated in realtime

• 96 leaderboards in BUNT

• Final output is constructed on-demand, no cache

• User scores are stored in sorted sets in Redis (ranking is automatic)

• Redis is an in-RAM key-value data store

Page 23: MongoDB at Dog on a Horse

Leaderboard Process

Page 24: MongoDB at Dog on a Horse

Scaling issue and resolution

Page 25: MongoDB at Dog on a Horse

Scaling Example: Buying Packs of Cards

• In order to support complex trading algorithms, each user profile needs to contain a reference to the owner’s card collection

Page 26: MongoDB at Dog on a Horse

Initial Structure of User Profile with Embedded Card Summary

Documents• Profile contains an

embedded document of card summaries

• When users buy cards, the profile can grow out of its allocated space

• MongoDB creates a new, bigger allocation for the user profile

Page 27: MongoDB at Dog on a Horse

Profiles were refactored to include only player IDs

• Finite number of players in the system, so size of player IDs list is limited

Page 28: MongoDB at Dog on a Horse

Basic Metrics

• On average, 1 pack sold per second

• Consistently top 10 grossing sports app

• Up to 30,000 requests per minute

• Up to 2,000 OPS

Page 29: MongoDB at Dog on a Horse

Conclusions• MongoDB great for apps, especially social

• JSON-ready data

• Normal NoSQL arguments

• For realtime leaderboards, Redis provides simple and fast “automatic sorting” of user scores

• Don’t embed documents if you hope for them to grow

• Easy to learn

Page 30: MongoDB at Dog on a Horse

We’re Hiring!

MongoDB+Py, Web, iOS, Android, App Producer, Project Management, QA