Successfully reported this slideshow.

MongoDB, Development and You

2,042 views

Published on

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).

Published in: Technology
  • Be the first to comment

MongoDB, Development and You

  1. 1. MongoTorino 2013 MongoDB, Development and You Mitch Pirtle! CTO Sounday Music! www.soundaymusic.com
  2. 2. 45 MINUTES?! Let’s get this thing going then.
  3. 3. Speaker Intro
  4. 4. 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
  5. 5. Sleeper Check!
  6. 6. Sounday Intro
  7. 7. 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
  8. 8. The Team
  9. 9. Ok, not really.
  10. 10. The Challenge
  11. 11. The Challenge ❖ “We’re gunning for a grant”! ❖ ❖ “It needs to be live soon” ! ❖ ❖ (zero time)! “We’re disrupting the industry”! ❖ ❖ (no money yet)! (no requirements)! “Wanna move to Cagliari?”
  12. 12. Ok, it’s not really that bad.
  13. 13. Well maybe.
  14. 14. Classic Startup Challenges ❖ Limited budget! ❖ Limited staff! ❖ Limited time! ❖ Zero chance for best practices during development
  15. 15. How I felt when accepting the challenge
  16. 16. How it actually looked
  17. 17. The Solution
  18. 18. 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
  19. 19. 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)
  20. 20. Solution: The database MongoDB • • • • • Document database! GridFS for large binary files! Scales vertically! Scales horizontally! Reduces male pattern baldness
  21. 21. 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
  22. 22. Sleeper Check!
  23. 23. The Good
  24. 24. 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
  25. 25. 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
  26. 26. The Bad
  27. 27. 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)
  28. 28. And lest we not forget…
  29. 29. The Ugly
  30. 30. 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?
  31. 31. 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!
  32. 32. 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
  33. 33. Example Time
  34. 34. User schema, when we started class Users extends Model { ! //protected $_schema = array() ! }
  35. 35. 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'), );
  36. 36. Database structure activities_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
  37. 37. One last thing
  38. 38. Behold, the mighty firehose
  39. 39. Whups, not that one
  40. 40. 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 }
  41. 41. 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.! ! ! ! ! ! :-)
  42. 42. Sleeper Check!
  43. 43. Stump the Speaker
  44. 44. Thank You! Mitch Pirtle mitch.pirtle@gmail.com http://about.me/mitchitized http://twitter.com/mitchitized http://github.com/spacemonkey

×