Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

OTA Platform with MongoDB


Published on

First Meetup (Hello Mongo) talks, Jakarta.

Published in: Technology

OTA Platform with MongoDB

  1. 1. OTA Platformwith MongoDBwith MongoDB talks 19 Jan 2013
  2. 2. About Our Application• One stop shopping OTA (Online Travel Agency) • Regular • Flash Deals• Various type of products • eg: hotels, flights, tours/activities, campaigns (flash deals), etc• Facilitate B2B travel
  3. 3. About Our Application
  4. 4. IS THAT IT?
  5. 5. About Our ApplicationTravel Ideas • Travel News, up-to-date info all around the world • Travel Tips • based on places (countries, cities, areas) • covers various aspects, such as overview, sightseeing, eating/restaurants, shopping and events • Travel Stories, submitted by members • Photos and Videos • Blog, monthly theme posts based on event calendar
  8. 8. Technology OverviewThese are stuff that we use behind our appsWeb Server : ApacheApplication : PHP CodeIgniter (PHP MVC Framework) Backbone.js (Javascript Framework) with its friends Require.js, Underscore.js, Mustache.js, jQueryDatabase : MongoDB
  9. 9. Why MongoDB?• It’s fast• Development speed time faster• No join, no relation• No sql injection worries (you bet)• Reduced database requests• Super flexible schema design • Fewer tables/collections used
  10. 10. What do we store inMongoDB? All datas are stored in MongoDB.Including important data such as bookings,inventory, etc.
  11. 11. Building the Apps...We will tell you guys howMongoDB helps us a lot
  12. 12. Saving huge amount of timeon database stuff spreadsheet is more than enoughdb structure alters and changesstraight on the code
  13. 13. With RDBMS approach, dynamicdata is pain in the a*s Embedded documents to the rescue This is how we handle dynamic data on our apps
  14. 14. Use Case• Hotels may have multiple contracts • One hotel contracts may have multiple bank accounts• Hotels may have multiple facilities • Hotel facilities have several categories
  15. 15. Schema Design MongoDB approach RDBMS approach more or less like two/three tables for reference data
  16. 16. And now the query...“get me hotels with its facilities which has BCA account in Jakarta only” RDBMS approach SELECT * FROM hotels INNER JOIN facilities .... INNER JOIN photos .... AND THEN JOIN the_banks .... AND OF COURSE JOIN the_locations .... AND JOIN the_city .... WHERE the_city IS “Jakarta” AND the_banks IS “Bank BCA” We all know JOINs are expensive. Use EXPLAIN on SQL to see it
  17. 17. And now the query...“get me hotels with its facilities which has BCA account in Jakarta only” MongoDB approach db.hotel.find( { “” : “Jakarta” , “” : “Bank BCA” } )One single query to fetch all the data we need
  18. 18. Be wise when choosing whichData Models are used Embedded documents not applied to all data model We use referenced model when it comes to very large record sets / documents
  19. 19. Model Referenced One-to-ManyRelationships between Documents data-modeling-publisher-and-booksNormalize the data, just like RDBMS approach butusing “fake” relationshipUse key/id to store references between two documents
  20. 20. Use Case• Each hotel may have multiple room types • One room type may have up to 10 photos/videos • Each room type have their rate/price • Room rates based on contract period (one or more years) • Room rates stored daily
  21. 21. Use CaseExample :A Hotel has 5 room typesEach Room type has 10 photosHotel contract period is one year5 room types x 10 photos = 50 documents5 room types x 365 room rates = 1825 documentsTotal documents for 1 hotel :1 + 5 + 50 + 1825 = 1881 documents
  22. 22. Use Case Example : Total documents for 1 hotel : 1 + 5 + 50 + 1825 = 1881 documents If we have 1500 hotels then 1881 x 1500 = 2.821.500What if we have more than 1500 hotels?What if a hotel have more than 5 room types?What if a room type has more than 15 photos?
  23. 23. And then we decided to separate thecollections that potentially has huge data example : room_rates, hotel_media, etc
  24. 24. More to see...• Other slides • •• Codes and Articles • • mongodb/
  25. 25. @hadiariawan hadi.ariawan