Scalable Event Analytics With MongoDB & Ruby On Rails
Scalable Event Analytics With MongoDB & Ruby On Rails
Data Source
Event
Event
Event
Query User
Data Source Event
Event
Report
Event
Event Analytics
Event Query
Event
Event
Data Source Report User
Event
Event
Event
Data Source
High Write Volume
Each new data source adds X requests per second
Data never stops arriving
MySQL
MySQL
“ Just ” a Rails
App
Rails default architecture
Performance
Bottleneck : Too much
load
MySQL
“ Just ” a Rails
App
Let’s add replication!
Replication
Replication
Replication
Sharding
Data Source Collection Server
MySQL
MySQL
MasterMySQL
Master
Master
Sharding
User Reporting Server
What about sharding?
Scalable Writes !
Sharding
Data Source Collection Server
MySQL
MySQL
MasterMySQL
Master
Master
Sharding
User Reporting Server
What about sharding?
Scalable Writes !
Sharding
Data Source Collection Server
MySQL
MySQL
MasterMySQL
Master
Master
Sharding
User Reporting Server
Development
Bottleneck :
Need to write custom
code
Key Value stores to the rescue?
MySQL
MySQL
Master
Cassandra
Master or
Voldemort
User Reporting Server
Key Value stores to the rescue?
Scalable Writes !
MySQL
MySQL
Master
Cassandra
Master or
Voldemort
User Reporting Server
Key Value stores to the rescue?
Scalable Writes !
MySQL
MySQL
Master
Cassandra
Master or
Voldemort
User Reporting Server
Development
Bottleneck :
Reporting is limited /
hard
Can I Hadoop my way out of this?
MySQL
MySQL
Master
Cassandra
Master or
Data Source Collection Server Voldemort
Hadoop
MySQL
Master
MySQL
MySQL
Master
Cassandra
Master or
Data Source Collection Server Voldemort
Hadoop
MySQL
Master
MySQL
MySQL
Master
Cassandra
Master or
Data Source Collection Server Voldemort
Hadoop
Flexible
Reports ! MySQL
Master
MySQL
MySQL
Master
Cassandra
Master or
Data Source Collection Server Voldemort
Hadoop
Flexible
Reports ! MySQL
Master
“ Just ” a Rails
App
MySQL
MySQL
Master
Cassandra
Master or
Data Source Collection Server Voldemort
Development
Bottleneck : Hadoop
Too many systems !
Flexible
Reports ! MySQL
Master
“ Just ” a Rails
App
MySQL
MySQL
Master
Master
MongoDB
MySQL
MySQL
Master
Master
MongoDB
MySQL
MySQL
Master
Master
MongoDB
Flexible
Reporting !
MongoDB!
“ Just ” a rails
app Scalable Writes !
MySQL
MySQL
Master
Master
MongoDB
Flexible
Reporting !
MongoD
App Server
Data Source
Passenger
Collection
Mongos
Nginx
Load
Balancer MongoD
Reporting
User
MongoD
Sharding !
MongoD
App Server
Data Source
Passenger
Collection
Mongos
Nginx
Load
Balancer MongoD
Reporting
User
MongoD
Sharding !
High
Concurrency
MongoD
App Server
Data Source
Passenger
Collection
Mongos
Nginx
Load
Balancer MongoD
Reporting
User
MongoD
Sharding !
MongoD
App Server
Data Source
Passenger
Collection
Mongos
Nginx
Load
Balancer MongoD
Reporting
User
MongoD
MongoDB Sharding
MongoDB Sharding
Replica Sets
let us scale
storage &
transaction
capacity for
each shard
MongoDB Sharding
Replica Sets
let us scale
storage &
transaction
capacity for
each shard
Mongos routes
transactions to
shards based on
“ shard key ”
MongoDB Sharding
Config servers
store
information
about which
shards exist
Replica Sets
let us scale
storage &
transaction
capacity for
each shard
Mongos routes
transactions to
shards based on
“ shard key ”
Inserting
3 Insert { ‘ name ’ :
bob }
Shard key ==
2 name
bob Shard 2
1 insert { ‘ name ’ :
bob }
Querying
3 Query { ‘ name ’ :
bob }
Shard key ==
2 name
bob Shard 2
1 Query { ‘ name ’ :
bob }
Map Reduce
2 2 2 2
1 Map - reduce ( … )
Working with Mongo
• MongoMapper makes it
look like ActiveRecord
•
• Documents are more
natural than rows in
many cases
•
• Map-Reduce rocks (but
needs better support
http://www.flickr.com/photos/elhamalawy/2526783078/
in rails)
Ruby
Mongo
Runs over all the objects in the views table, counting ho
• It’s fast!
– 63ms – Average response time for sending data to
server
– 93ms – Average response time for displaying reports