ota platform with mongodb

25
OTA Platform with MongoDB with MongoDB talks 19 Jan 2013

Upload: hadi-ariawan

Post on 02-Jul-2015

1.443 views

Category:

Technology


0 download

DESCRIPTION

First Meetup (Hello Mongo) talks, Jakarta.

TRANSCRIPT

Page 1: OTA Platform with MongoDB

OTA Platformwith MongoDBwith MongoDB

talks 19 Jan 2013

Page 2: OTA Platform with MongoDB

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

About Our Application

Page 4: OTA Platform with MongoDB

IS THAT IT?

Page 5: OTA Platform with MongoDB

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

TRAVEL BUSINESSBREAKTHROUGH

Page 7: OTA Platform with MongoDB

SOON ON YOUR BROWSER

Page 8: OTA Platform with MongoDB

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

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

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

We will tell you guys how MongoDB helps us a lot

Building the Apps...

Page 12: OTA Platform with MongoDB

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

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

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

Schema DesignRDBMS approach

more or less like this...

plus two/three tables for reference data

MongoDB approach

Page 16: OTA Platform with MongoDB

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

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

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

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

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

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

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

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

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

@hadiariawanhadi.ariawan

http://about.me/hadiariawan