migrating from mysql to mongodb
DESCRIPTION
Migrating from MySQL to MongoDB based on a true storyTRANSCRIPT
![Page 1: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/1.jpg)
Migrating from MySQL
to MongoDB
Based on a true story
![Page 2: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/2.jpg)
Starting Point
Existing System
![Page 3: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/3.jpg)
Starting Point
Requirements for replacement:
• Store data
• High performance
o worldwide access
o multiple physical locations
o read heavy application
• Simple to use o No DBA...
• MI o real-time reporting without affecting production
![Page 4: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/4.jpg)
• Availability and Partition Tolerance o from CAP
o by default Consistency not Availability...
• Document-Orientated
o called from OOPHP
• Simple querying using JSON
o benefit over CouchDB which needs MapReduce
• Simple multi-node setup
• MongoLab.com o web interface for prototyping
So why MongoDB?
![Page 5: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/5.jpg)
Read Preference
Defaults to primary (strongly consistent)
Other options allow eventual consistency
primaryPreferred
secondary
secondaryPreferred
![Page 6: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/6.jpg)
New Architecture
Single primary, multiple read members
![Page 7: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/7.jpg)
What are the other members?
One Delayed member provides a rolling
backup by maintaining a dataset, delay is
limited by the size of the oplog
One Hidden member provides access for MI
(and also used for dumping in this scenario)
![Page 8: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/8.jpg)
Automatic Failover
Primary is FUBAR, new primary is elected
![Page 9: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/9.jpg)
Automatic Failover
Had experience of this in production. It's magic.
Remaining replica set members will vote and
elect a new primary, which will start taking
writes. (PHP extension issue)
Replica set members that have been out of the
cluster will recover automatically on rejoining
o If you've gone past the oplog window then it's a manual
process
![Page 10: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/10.jpg)
Sharding, and why we didn't
• Sharding divides the data set and
distributes the data over multiple servers, or
shards
• Necessary when o data exceeds max for single instance (based on disk
space)
o the Working Set exceeds available RAM
o single instance can’t deal with writes (would have to
be a lot)
• We had none of these and Sharding adds
complexity
![Page 11: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/11.jpg)
Sharding Architecture
http://docs.mongodb.org/manual/core/sharded-cluster-architectures-production/
![Page 12: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/12.jpg)
Sharding Availability
Each Shard would need a Replica Set
containing at least 3 members to achieve the
same level of availability as our non-sharded
architecture.
In addition if one or two of the Config Servers
are unavailable chunk migration and chunk
splitting are suspended
![Page 13: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/13.jpg)
DataBase Design
• Schemaless means that the structure and
the content of the “record” are held for each
“row”
o long key names add up
o we used single chars and a lookup table
• Collections
o Can think of them as “buckets” rather than tables
o Contain similar records by design but it’s not
enforced
![Page 14: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/14.jpg)
Management Information
• Different conceptually in NoSQL databases
due to the way they are queried, returning
JSON
• Traditional working through a query tool is
less intuitive (although MongoVUE is quite
good)
• This lead us to replace our SQL script ->
Excel -> Graph process (yuck)
• MapReduce, powerful but a steep learning
curve
![Page 15: Migrating from MySQL to MongoDB](https://reader035.vdocuments.mx/reader035/viewer/2022080209/547cfc09b4af9fa5158b51db/html5/thumbnails/15.jpg)
Conclusions
MongoDB is ace
Questions?