ota platform with mongodb
DESCRIPTION
First Meetup (Hello Mongo) talks, Jakarta.TRANSCRIPT
OTA Platformwith MongoDBwith MongoDB
talks 19 Jan 2013
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
About Our Application
IS THAT IT?
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
TRAVEL BUSINESSBREAKTHROUGH
SOON ON YOUR BROWSER
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
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
What do we store in MongoDB?
All datas are stored in MongoDB.
Including important data such as bookings, inventory, etc.
We will tell you guys how MongoDB helps us a lot
Building the Apps...
Saving huge amount of time on database stuff
spreadsheet is more than enough
db structure alters and changes straight on the code
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
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
Schema DesignRDBMS approach
more or less like this...
plus two/three tables for reference data
MongoDB approach
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
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
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
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
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
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
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
And then we decided to separate the collections that potentially has huge data
example : room_rates, hotel_media, etc
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/
@hadiariawanhadi.ariawan
http://about.me/hadiariawan