Building Social Inbox, using MongoDB

Post on 15-Jul-2015

844 views 2 download

Tags:

Transcript of Building Social Inbox, using MongoDB

Building A Practical Social Inbox

Using MongoDB

Dec 9th , 2014

10. 30 am EST

#suyatiwebinar

OUR

SPEAKER

Introduction to MongoDB

What are Social Inboxes? What are the

different types of Social Inboxes?

Challenges in building Social Inboxes

Patterns for building Social Inboxes

Implementing a Write intensive Social

Inbox

Introduction to Mongologue

OUR

AGENDA

Humongous Data

PERFORMANCE, AVAILABILITY, AUTO-SCALING

http://www.mongodb.org/downloads

http://try.mongodb.org

http://docs.mongodb.org/manual

MONGODB

MongoDB stores data in the form of documents

MongoDB stores all documents in collections. Collections are analogous to tables in Relational DBs

WHAT IS

SOCIALINBOX

Read/Write requests Volume Performance

Real Time User Experience

CONSIDERATIONS

Creates Posts (Write) Reads Timeline (Read) Follows Other Users Gets Followed by other Users

A USER

Real Time Writes and Reads Sorting Posts Paging and Delivery

AN

INBOX

“An Average Tweet makes it to about 254 inboxes”

• Duplication for performance• Parallel for scalability

THE MYTH OFNORMALIZED DATA

Fan-out on Read Fan-out on Write Fan-out on Write with Buckets

SCHEMA

DESIGNS

SCHEMASFan out on Read Fan out on Write

Send Message Performance

BestGood

Shard per recipientMultiple writes

Read Inbox PerformanceWorst

Broadcast all shardsRandom reads

GoodSingle shard

Random reads

Data SizeBest

Message stored onceWorst

Copy per recipient

var user = {"name": "john", "id": 1}show collectionsdb.testUsers.save(user)show collectionsdb.testUsers.find()

SOME

CODE

Ensuring everything's at arm's lengthLET’S TALK

SCHEMA

Creates Posts (Write) Reads Timeline (Read) Follows Other Users Gets Followed by other Users

A USER

var user = {"name": "john", "followers":[],"following":[]

}db.users.save(user)db.users.find()

THE

USERDOCUMENT

var post = {"from": "john", "date":new Date(),"message":"hello"

}

THE

POSTDOCUMENT

db.shardCollection("mongodbdays.inbox", {"recipient": 1, "sent":1})

var post = {"from": "john", "date":new Date(),"message":"hello"

}

var user = db.users.findOne({name: post.from})

for(follower in user.followers) {post.to = follower;db.inbox.insert(post)

}

CREATING A

POST

db.inbox.find ({to: "john"}).sort({ sent:-1})

RETREIVING THE

POST

A shard is a replica set or a single mongodthat contains a subset of the data for the sharded cluster.

SHARDS

db.shardCollection("test.inbox", {"to": 1, "sent":1})SHARDS

Groups Unfollow / Block Media in Posts Comments, Likes

https://github.com/suyati/mongologue

GOING

FURTHER