mongodb, development and you
DESCRIPTION
My talk at MongoTorino about how the use of MongoDB empowers your development teams, as well as tips and tricks to get around common pitfalls (and not so common challenges).TRANSCRIPT
MongoTorino 2013
MongoDB, Development and You
Mitch Pirtle!CTO Sounday Music!www.soundaymusic.com
45 MINUTES?! Let’s get this thing going then.
Speaker Intro
About Me❖ American, living in Turin!❖ CTO at Sounday Music!❖ Mongo Master!❖ Joomla! Founder!❖ Contributor to many FOSS!❖ Family man!❖ Coach (Giaguari Torino)!❖ Musician!❖ Longboarder
Sleeper Check!
Sounday Intro
Sounday in 2013❖ Growing community of music
professionals!
❖ Integrated with many social media platforms!
❖ Very large binary files (audio)!
❖ 100% UGC!
❖ e.commerce B2C, C2C!
❖ Based in Torino!
❖ Engineering based in Cagliari
The Team
Ok, not really.
The Challenge
The Challenge❖ “We’re gunning for a grant”!
❖ (no money yet)!
❖ “It needs to be live soon” !
❖ (zero time)!
❖ “We’re disrupting the industry”!
❖ (no requirements)!
❖ “Wanna move to Cagliari?”
Ok, it’s not really that bad.
Well maybe.
Classic Startup Challenges
❖ Limited budget!
❖ Limited staff!
❖ Limited time!
❖ Zero chance for best practices during development
How I felt when accepting the challenge
How it actually looked
The Solution
The Solution
❖ Single, RESTful base platform (web, mobile, partners)!
❖ Document database!
❖ Store media in database for simplicity, portability!
❖ Ability to break out separate services when scale needed!
❖ Tethered cloud for initial deployment
Solution: The application
Lithium
• Super lightweight PHP framework!• RAD!• MVC!• Promiscuously opinionated!• Post-relational!• Fully leverages PHP 5.3+!• Cherry-picker methodology (mix of
functional, object, aspect, and more)
Solution: The database
MongoDB
• Document database!• GridFS for large binary files!• Scales vertically!• Scales horizontally!• Reduces male pattern baldness
Solution: The approach
Agile, Xtreme
• Quick, iterative steps!• Constant refactoring!• Captured features during
implementation!• Pair programming!• Local, development and production
environments!• Development and production
environments mirrored!• Dedication to DRY
Sleeper Check!
The Good
Lithium saved our bacon
❖ Extremely quick to get bootstrapped and running a base platform!
❖ Many libraries available for specific needs!
❖ Natively talks to non-relational databases!
❖ Intelligent code layout, encourages best practices!
❖ Adapters, filters, this stuff is the shizzle
MongoDB saved our bacon, with eggs
❖ Simple document structure made for extremely simple models!
❖ Better matched with the objects used in our apps!
❖ GridFS made storing media dead simple!
❖ Being schemaless allowed us to iterate rapidly!
❖ After launch, we completely forgot about MongoDB from an operational standpoint
The Bad
The Bad
❖ Hey remember how easy it is to change your document schemas?!
❖ Loosely-typed language and database makes for fun!!
❖ Hope you love the command line. (limited tools)
And lest we not forget…
The Ugly
The Ugly
❖ What do you mean, ‘no need for constraints’?!
❖ Hey this GridFS database is freaking ginormous.!
❖ I’ve never seen that happen before.!
❖ What, there’s no more SQL? Then who’s to blame when something breaks?
What We Learned
❖ Our code was significantly lighter!
❖ This slim codebase is extremely fast!
❖ Smaller codebase == fewer bugs!
❖ GridFS combined with metadata is really powerful!
❖ Atomic documents + working memory = TO INFINITY AND BEYOND!
What Else We Learned
❖ Shift responsibilities from tools to developers!
❖ Testing and documentation are NOT OPTIONAL!
❖ Define models, even when iterating rapidly in a schemaless environment!
❖ Consider backup and operational requirements before you get started
Example Time
User schema, when we started
class Users extends Model { ! //protected $_schema = array() !}
User schema, today protected $_schema = array( '_id' => array('type' => 'id'), 'name' => array('type' => 'string'), 'username' => array('type' => 'string'), 'email' => array('type' => 'string'), 'password' => array('type' => 'string'), 'salt' => array('type' => 'string'), 'facebook_id' => array('type' => 'string'), 'date_created' => array('type' => 'date'), 'registration_source' => array('type' => 'string'), 'active' => array('type' => 'boolean', 'default' => false), // to make sure the account is live 'status' => array('type' => 'string'), 'mvadmin' => array('type' => 'boolean', 'default' => false), 'pufadmin' => array('type' => 'boolean', 'default' => false), 'resetadmin' => array('type' => 'boolean', 'default' => false), 'profile' => array('type' => 'string'), 'avatar' => array('type' => 'string'), 'enabled' => array('type' => 'string'), 'address' => array('type' => 'array'), 'vat' => array('type' => 'string'), 'url' => array('type' => 'string'), 'services' => array('type' => 'array'), 'likes' => array('type' => 'array'), // Polymorphic associations 'moderated' => array('type' => 'boolean'), 'follows' => array('type' => 'array'), 'last_login' => array('type' => 'date'), 'edit_time' => array('type' => 'date'), 'last_ip' => array('type' => 'string'), 'login_counter' => array('type' => 'integer'), 'is_legacy' => array('type' => 'boolean'), 'legacy_id' => array('type' => 'integer'), 'partners' => array('type' => 'array'), );
Database structureactivities_log!admin_bmu_calendars!admin_landing_pages!admin_notifications!artists!banlists!blacklists!blogs!communications!db_logs!engineers!events!fs.chunks!fs.files!galleries!job_applications!job_songs!jobs!
labels!media!messages!news!payments!playlists!sequence!services!sounday_contest_songs!sounday_contest_users!sounday_contest_videos!studios!system.indexes!temp_lookups!tokens!users!venues!videos
One last thing
Behold, the mighty firehose
Whups, not that one
rs0:PRIMARY> db.firehose.stats() { "ns" : "sounday_analytics_prod.firehose", "count" : 3146600, "size" : 10086355648, "avgObjSize" : 3205.4775465581897, "storageSize" : 10830245856, "numExtents" : 26, "nindexes" : 1, "lastExtentSize" : 2146426864, "paddingFactor" : 1, "systemFlags" : 1, "userFlags" : 0, "totalIndexSize" : 113204896, "indexSizes" : { "_id_" : 113204896 }, "ok" : 1 }
Yeah, I said firehose. Got a problem wit dat?
Console time
If you wanted to see this part of the talk, you should have attended the session.!!! ! ! ! :-)
Sleeper Check!
Stump the Speaker
Mitch Pirtle [email protected] http://about.me/mitchitized http://twitter.com/mitchitized http://github.com/spacemonkey
Thank You!