Download - OTA Platform with MongoDB
![Page 1: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/1.jpg)
OTA Platformwith MongoDBwith MongoDB
talks 19 Jan 2013
![Page 2: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/2.jpg)
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
![Page 3: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/3.jpg)
About Our Application
![Page 4: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/4.jpg)
IS THAT IT?
![Page 5: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/5.jpg)
About Our Application
• 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
Travel Ideas
![Page 6: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/6.jpg)
TRAVEL BUSINESSBREAKTHROUGH
![Page 7: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/7.jpg)
SOON ON YOUR BROWSER
![Page 8: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/8.jpg)
Technology OverviewThese are stuff that we use behind our apps
Web Server : Apache
Application : PHP
Database : MongoDB
CodeIgniter (PHP MVC Framework)Backbone.js (Javascript Framework) with its friendsRequire.js, Underscore.js, Mustache.js, jQuery
![Page 9: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/9.jpg)
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
![Page 10: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/10.jpg)
What do we store in MongoDB?
All datas are stored in MongoDB.
Including important data such as bookings, inventory, etc.
![Page 11: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/11.jpg)
We will tell you guys how MongoDB helps us a lot
Building the Apps...
![Page 12: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/12.jpg)
Saving huge amount of time on database stuff
spreadsheet is more than enough
db structure alters and changes straight on the code
![Page 13: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/13.jpg)
With RDBMS approach, dynamic data is pain in the a*s
Embedded documents to the rescue
This is how we handle dynamic data on our apps
![Page 14: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/14.jpg)
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
![Page 15: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/15.jpg)
Schema DesignRDBMS approach
more or less like this...
plus two/three tables for reference data
MongoDB approach
![Page 16: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/16.jpg)
And now the query...
RDBMS approachSELECT * FROM hotelsINNER 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”
“get me hotels with its facilities which has BCA account in Jakarta only”
We all know JOINs are expensive.Use EXPLAIN on SQL to see it
![Page 17: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/17.jpg)
MongoDB approach
db.hotel.find( { “locations.city” : “Jakarta” , “contracts.banks.name” : “Bank BCA” } )
And now the query...
“get me hotels with its facilities which has BCA account in Jakarta only”
One single query to fetch all the data we need
![Page 18: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/18.jpg)
Be wise when choosing which Data Models are used
Embedded documents not applied to all data model
We use referenced model when it comes to very large record sets / documents
![Page 19: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/19.jpg)
http://docs.mongodb.org/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/#data-modeling-publisher-and-books
Model Referenced One-to-Many Relationships between Documents
Normalize the data, just like RDBMS approach but using “fake” relationship
Use key/id to store references between two documents
![Page 20: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/20.jpg)
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
![Page 21: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/21.jpg)
Use CaseExample :A Hotel has 5 room typesEach Room type has 10 photosHotel contract period is one year
5 room types x 10 photos = 50 documents5 room types x 365 room rates = 1825 documents
Total documents for 1 hotel :1 + 5 + 50 + 1825 = 1881 documents
![Page 22: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/22.jpg)
Use CaseExample :
Total documents for 1 hotel :1 + 5 + 50 + 1825 = 1881 documents
What 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?
If we have 1500 hotels then 1881 x 1500 = 2.821.500
![Page 23: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/23.jpg)
And then we decided to separate the collections that potentially has huge data
example : room_rates, hotel_media, etc
![Page 24: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/24.jpg)
More to see...
• Other slides
• http://www.slideshare.net/h.ariawan/okezonecom-inline-voting-system
• http://www.slideshare.net/h.ariawan/sekilas-php-mongodb
• Codes and Articles
• https://github.com/hadiariawan/monode-crud
• http://hadiariawan.web.id/2012/06/27/simple-crud-web-using-nodejs-and-mongodb/
![Page 25: OTA Platform with MongoDB](https://reader033.vdocuments.us/reader033/viewer/2022052508/559518001a28ab84418b461f/html5/thumbnails/25.jpg)
@hadiariawanhadi.ariawan
http://about.me/hadiariawan