SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Downloaden Sie, um offline zu lesen
Building Modn
Web Acaons
@spf13Steve Francia
AKA
Chief Evangelist @
responsible for Developer Experience:
drivers, integrations, web & technical writing
๏ History of web development
๏ Picking the right data model
๏ Modern DB interaction
๏ Modern Web Scale
Agda
What is a modn Web A?
What is a modn Web A?
If you don't ow whe
you've come from,
you don't ow whe
you are. - James Burke
te 90’s
๏Web is born
๏Web development mostly
done in perl or C
๏Everyone is a webmaster
๏Relational databases
r ’s
๏ Web growth
redefines scale
๏ Javascript avoided
๏ Dynamic languages come of age
๏ LAMP
๏ Everyone is a PHP programmer
๏ Relational databases
Mid ’s
๏ Social re-
redefines scale
๏ Multimedia rules
๏ Heavy caching (memcache) required LAM(m)P
๏ Frameworks (Ruby on Rails) with heavy
database abstractions en vogue
๏ Everyone is a OO programmer
๏ Relational databases*
is is whe  all
falls apa
Condons
๏ Web users exponentially increasing
๏ Excessive layering causes applications
to be slower
๏ Social (dynamic data) limits use of
caching crutch
๏ Cost per byte decreasing rapidly
๏ Data growing in size & complexity
Symptoms
๏ Over abstraction
๏ Agile development unsustainable
๏ Needlessly complex
architectures
๏ Memcache
2010 trds
(Areßing r Ißues)
๏Horizontal scale
๏Variety of Choices
(LAMP no more)
๏Specializing
Raonal designed for one ing,
used for hing
What is a modn Web A?
What is a modn Web A?
What do we lk for in
a database?
๏ Right structure to match my
data
๏ Performance & Scale
๏ Features that enable me as a
developer
K Queson:
WHAT IS A RECORD?
K Value
๏ One-dimensional storage
๏ Single value is a blob
๏ Query on key only
๏ Some support secondary indexes
๏ No schema
๏ Value cannot be updated, only replaced
Key Blob
Cassandra, Redis, MemcacheD, Riak, DynamoDB
Raonal๏ Query on any field
๏ In-place updates
๏ Two-dimensional storage
๏ Each field contains a single value
๏ Very structured schema (table)
๏ Normalization process requires many tables,
joins, indexes, and poor data locality
Primary
Key
Oracle, MSSQL, MySQL, PostgreSQL, DB2
Documt๏ N-dimensional storage
๏ Each field can contain 0, 1,
many, or embedded values
๏ Query on any field & level
๏ Flexible schema
๏ Inline updates
๏ Embedding related data has optimal data locality,
requires fewer indexes, has better performance
_id
MongoDB, CouchDB, RethinkDB
Raonal design
Documt design
Example Blog Post doc
{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
author : "steve",
date : "Sat Apr 24 2013 19:47:11",
text : "About MongoDB...",
tags : [ "tech", "databases" ],
comments : [
	 {
	 		 author : "Fred",
	 		 date : "Sat Apr 25 2013 20:51:03 GMT-0700",
	 		 text : "Best Post Ever!"
	 	}
]
}
What is a modn Web A?
What is a modn Web A?
MongoDB spks your ngauage
๏ Drivers in 14+ languages
๏ Interface is natural and
idiomatic for each language
๏ Document natively maps to
map/hash/object
array/dict/struct
place1 = {

 name : "10gen HQ",

 address : "229 W 43rd St. 5th Floor",

 city : "New York",

 zip : "10036",
tags : [ "business", "awesome" ]
}
Start with an object
(or array, hash, dict, etc)
Inserting the record
Initial Data Load
> db.places.insert(place1)
> db.places.insert(place1)
Querying
> db.places.findOne({ zip: "10036",
tags: "awesome" })
> db.places.find({tags: [ "rad", "awesome" ]})
{

 name : "10gen HQ",

 address : "229 W 43rd St. 5th Floor",

 city : "New York",

 zip : "10036",
tags : [ "business", "awesome" ]
}
Updating
> db.places.update(
{name : "10gen HQ"},
{ $push :
{ comments :
{ author : "steve",
date : 6/26/2013, 
text : "Office hours are great!"
}
}
}
)
Nested documents
// Index nested documents
> db.places.ensureIndex({ "comments.author":1 }) // optional
> db.places.find({'comments.author':'Fred'})
{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
name : "10gen HQ",

 address : "229 W 43rd St. 5th Floor",

 city : "New York",

 zip : "10036",
comments : [ {
author : "Fred",
date : "Sat Apr 25 2013 20:51:03",
text : "Best Place Ever!"

 } ]
}
Multiple values
// Index on tags (multi-key index)
> db.places.ensureIndex({ tags: 1}) // optional
> db.places.find( { tags: 'tech' } )
{
_id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
name : "10gen HQ",

address : "229 W 43rd St. 5th Floor",

 city : "New York",

 zip : "10036",
tags : [ "business", "awesome", "tech" ],
}
Paginating Places in JS
per_page = 10;
page_num = 3;
places = db.places
.find({ "city" : "new york" })
.sort({ "ts" : -1 })
.skip((page_num - 1) * per_page)
.limit(per_page);
Paginating Places in Ruby
@per_page = 10
@page_num = 3
@places = @db.places
.find({ :city => "new york" })
.sort({ :ts => -1 })
.skip(( @page_num - 1 ) * @per_page)
.limit(@per_page)
ch ftures๏ Rich query language
๏ GeoSpatial
๏ Text search
๏ Flexible schema
๏ Aggregation & MapReduce
๏ GridFS
(distributed & replicated file storage)
๏ Integration with Hadoop, Storm, Solr & more
Database ndscape
Scalability&Performance
Depth of Functionality
MongoDB
Key Value
RDBMS
NoSQL popu
NoSQL popu
NoSQL popu
What is a modn Web A?
What is a modn Web A?
Scabi Needs
๏ Data is highly available
๏ Data is consistent
๏ Performant
(caching unnecessary)
Difft Aroaches
๏
MultiMaster
๏
Peer to peer
๏
Has Conflicts
๏
Ring based
approach
combines high
availability and
distribution
๏
Complex
application logic
๏
Single Master
๏
Consistent
๏
Slaves have
delayed writes
๏
High availability
๏
No scalable
solution
๏
Single Master
๏
Consistent
๏
Secondaries have
delayed writes
๏
High availability
๏
Range based
distribution
MongoDB : bui to scale
๏ Intelligent replication
๏ Automatic partitioning of data
(user configurable)
๏ Horizontal Scale
๏ Targeted Queries
๏ Parallel Processing
Igt Repcaon
Node 1
Secondary
Node 2
Secondary
Node 3
Primary
Replication
Heartbeat
Replication
Scable Archecture
Node 1
Secondary
Config
Server
Node 1
Secondary
Config
Server
Node 1
Secondary
Config
Server
Shard Shard Shard
Mongos
App Server
Mongos
App Server
Mongos
App Server
High Avaibi in Shards
Shard
Primary
Secondary
Secondary
Shard
orMongod
x
Targed Requests
Shard Shard Shard
Mongos
1
2
3
4
Pall proceßing
Shard Shard Shard
Mongos
1
2 2 2
4 44
3 3 3
6
5
What is a modn Web A?
e g database
to t your data
e g database
for YOUR dopmt
e g Database
for scale & Pfoance
Gng staed
sy deploymt
๏ Heroku
๏ Rackspace
๏ Amazon
๏ Engine Yard
๏ App Fog
๏ ServerGrove
๏ Azure
๏ Nodejitsu
Indust acaon
๏ Media &
Entertainment
๏ Retail
๏ Social
๏ Finance
๏ Gaming
๏ Insurance
๏ Healthcare
๏ Government
๏ Archiving
๏ Telecom
๏ Education
E IF YOU KED !
Questions?
http://spf13.com
http://github.com/spf13
@spf13
#DevCon5
Modern Web Applications with MongoDB

Weitere ähnliche Inhalte

Mehr von Steven Francia

Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Steven Francia
 
Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Steven Francia
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with GoSteven Francia
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Steven Francia
 
Modern Database Systems (for Genealogy)
Modern Database Systems (for Genealogy)Modern Database Systems (for Genealogy)
Modern Database Systems (for Genealogy)Steven Francia
 
Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopSteven Francia
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012Steven Francia
 
Big data for the rest of us
Big data for the rest of usBig data for the rest of us
Big data for the rest of usSteven Francia
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
Replication, Durability, and Disaster Recovery
Replication, Durability, and Disaster RecoveryReplication, Durability, and Disaster Recovery
Replication, Durability, and Disaster RecoverySteven Francia
 
Multi Data Center Strategies
Multi Data Center StrategiesMulti Data Center Strategies
Multi Data Center StrategiesSteven Francia
 
NoSQL databases and managing big data
NoSQL databases and managing big dataNoSQL databases and managing big data
NoSQL databases and managing big dataSteven Francia
 
MongoDB, Hadoop and Humongous Data
MongoDB, Hadoop and Humongous DataMongoDB, Hadoop and Humongous Data
MongoDB, Hadoop and Humongous DataSteven Francia
 
Hybrid MongoDB and RDBMS Applications
Hybrid MongoDB and RDBMS ApplicationsHybrid MongoDB and RDBMS Applications
Hybrid MongoDB and RDBMS ApplicationsSteven Francia
 
Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011Steven Francia
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsSteven Francia
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011Steven Francia
 

Mehr von Steven Francia (20)

Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
 
Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with Go
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013
 
Modern Database Systems (for Genealogy)
Modern Database Systems (for Genealogy)Modern Database Systems (for Genealogy)
Modern Database Systems (for Genealogy)
 
Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and Hadoop
 
Future of data
Future of dataFuture of data
Future of data
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012
 
Big data for the rest of us
Big data for the rest of usBig data for the rest of us
Big data for the rest of us
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Replication, Durability, and Disaster Recovery
Replication, Durability, and Disaster RecoveryReplication, Durability, and Disaster Recovery
Replication, Durability, and Disaster Recovery
 
Multi Data Center Strategies
Multi Data Center StrategiesMulti Data Center Strategies
Multi Data Center Strategies
 
NoSQL databases and managing big data
NoSQL databases and managing big dataNoSQL databases and managing big data
NoSQL databases and managing big data
 
MongoDB, Hadoop and Humongous Data
MongoDB, Hadoop and Humongous DataMongoDB, Hadoop and Humongous Data
MongoDB, Hadoop and Humongous Data
 
MongoDB and hadoop
MongoDB and hadoopMongoDB and hadoop
MongoDB and hadoop
 
MongoDB for Genealogy
MongoDB for GenealogyMongoDB for Genealogy
MongoDB for Genealogy
 
Hybrid MongoDB and RDBMS Applications
Hybrid MongoDB and RDBMS ApplicationsHybrid MongoDB and RDBMS Applications
Hybrid MongoDB and RDBMS Applications
 
Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and Transactions
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 

Kürzlich hochgeladen (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Modern Web Applications with MongoDB

  • 2. @spf13Steve Francia AKA Chief Evangelist @ responsible for Developer Experience: drivers, integrations, web & technical writing
  • 3. ๏ History of web development ๏ Picking the right data model ๏ Modern DB interaction ๏ Modern Web Scale Agda
  • 4. What is a modn Web A?
  • 5. What is a modn Web A?
  • 6. If you don't ow whe you've come from, you don't ow whe you are. - James Burke
  • 7. te 90’s ๏Web is born ๏Web development mostly done in perl or C ๏Everyone is a webmaster ๏Relational databases
  • 8. r ’s ๏ Web growth redefines scale ๏ Javascript avoided ๏ Dynamic languages come of age ๏ LAMP ๏ Everyone is a PHP programmer ๏ Relational databases
  • 9. Mid ’s ๏ Social re- redefines scale ๏ Multimedia rules ๏ Heavy caching (memcache) required LAM(m)P ๏ Frameworks (Ruby on Rails) with heavy database abstractions en vogue ๏ Everyone is a OO programmer ๏ Relational databases*
  • 10. is is whe  all falls apa
  • 11. Condons ๏ Web users exponentially increasing ๏ Excessive layering causes applications to be slower ๏ Social (dynamic data) limits use of caching crutch ๏ Cost per byte decreasing rapidly ๏ Data growing in size & complexity
  • 12. Symptoms ๏ Over abstraction ๏ Agile development unsustainable ๏ Needlessly complex architectures ๏ Memcache
  • 13. 2010 trds (Areßing r Ißues) ๏Horizontal scale ๏Variety of Choices (LAMP no more) ๏Specializing
  • 14. Raonal designed for one ing, used for hing
  • 15. What is a modn Web A?
  • 16. What is a modn Web A?
  • 17. What do we lk for in a database? ๏ Right structure to match my data ๏ Performance & Scale ๏ Features that enable me as a developer
  • 19. K Value ๏ One-dimensional storage ๏ Single value is a blob ๏ Query on key only ๏ Some support secondary indexes ๏ No schema ๏ Value cannot be updated, only replaced Key Blob Cassandra, Redis, MemcacheD, Riak, DynamoDB
  • 20. Raonal๏ Query on any field ๏ In-place updates ๏ Two-dimensional storage ๏ Each field contains a single value ๏ Very structured schema (table) ๏ Normalization process requires many tables, joins, indexes, and poor data locality Primary Key Oracle, MSSQL, MySQL, PostgreSQL, DB2
  • 21. Documt๏ N-dimensional storage ๏ Each field can contain 0, 1, many, or embedded values ๏ Query on any field & level ๏ Flexible schema ๏ Inline updates ๏ Embedding related data has optimal data locality, requires fewer indexes, has better performance _id MongoDB, CouchDB, RethinkDB
  • 24. Example Blog Post doc { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "steve", date : "Sat Apr 24 2013 19:47:11", text : "About MongoDB...", tags : [ "tech", "databases" ], comments : [ { author : "Fred", date : "Sat Apr 25 2013 20:51:03 GMT-0700", text : "Best Post Ever!" } ] }
  • 25. What is a modn Web A?
  • 26. What is a modn Web A?
  • 27. MongoDB spks your ngauage ๏ Drivers in 14+ languages ๏ Interface is natural and idiomatic for each language ๏ Document natively maps to map/hash/object array/dict/struct
  • 28. place1 = { name : "10gen HQ", address : "229 W 43rd St. 5th Floor", city : "New York", zip : "10036", tags : [ "business", "awesome" ] } Start with an object (or array, hash, dict, etc)
  • 29. Inserting the record Initial Data Load > db.places.insert(place1) > db.places.insert(place1)
  • 30. Querying > db.places.findOne({ zip: "10036", tags: "awesome" }) > db.places.find({tags: [ "rad", "awesome" ]}) { name : "10gen HQ", address : "229 W 43rd St. 5th Floor", city : "New York", zip : "10036", tags : [ "business", "awesome" ] }
  • 31. Updating > db.places.update( {name : "10gen HQ"}, { $push : { comments : { author : "steve", date : 6/26/2013, text : "Office hours are great!" } } } )
  • 32. Nested documents // Index nested documents > db.places.ensureIndex({ "comments.author":1 }) // optional > db.places.find({'comments.author':'Fred'}) { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), name : "10gen HQ", address : "229 W 43rd St. 5th Floor", city : "New York", zip : "10036", comments : [ { author : "Fred", date : "Sat Apr 25 2013 20:51:03", text : "Best Place Ever!" } ] }
  • 33. Multiple values // Index on tags (multi-key index) > db.places.ensureIndex({ tags: 1}) // optional > db.places.find( { tags: 'tech' } ) { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), name : "10gen HQ", address : "229 W 43rd St. 5th Floor", city : "New York", zip : "10036", tags : [ "business", "awesome", "tech" ], }
  • 34. Paginating Places in JS per_page = 10; page_num = 3; places = db.places .find({ "city" : "new york" }) .sort({ "ts" : -1 }) .skip((page_num - 1) * per_page) .limit(per_page);
  • 35. Paginating Places in Ruby @per_page = 10 @page_num = 3 @places = @db.places .find({ :city => "new york" }) .sort({ :ts => -1 }) .skip(( @page_num - 1 ) * @per_page) .limit(@per_page)
  • 36. ch ftures๏ Rich query language ๏ GeoSpatial ๏ Text search ๏ Flexible schema ๏ Aggregation & MapReduce ๏ GridFS (distributed & replicated file storage) ๏ Integration with Hadoop, Storm, Solr & more
  • 37. Database ndscape Scalability&Performance Depth of Functionality MongoDB Key Value RDBMS
  • 41. What is a modn Web A?
  • 42. What is a modn Web A?
  • 43. Scabi Needs ๏ Data is highly available ๏ Data is consistent ๏ Performant (caching unnecessary)
  • 44. Difft Aroaches ๏ MultiMaster ๏ Peer to peer ๏ Has Conflicts ๏ Ring based approach combines high availability and distribution ๏ Complex application logic ๏ Single Master ๏ Consistent ๏ Slaves have delayed writes ๏ High availability ๏ No scalable solution ๏ Single Master ๏ Consistent ๏ Secondaries have delayed writes ๏ High availability ๏ Range based distribution
  • 45. MongoDB : bui to scale ๏ Intelligent replication ๏ Automatic partitioning of data (user configurable) ๏ Horizontal Scale ๏ Targeted Queries ๏ Parallel Processing
  • 46. Igt Repcaon Node 1 Secondary Node 2 Secondary Node 3 Primary Replication Heartbeat Replication
  • 47. Scable Archecture Node 1 Secondary Config Server Node 1 Secondary Config Server Node 1 Secondary Config Server Shard Shard Shard Mongos App Server Mongos App Server Mongos App Server
  • 48. High Avaibi in Shards Shard Primary Secondary Secondary Shard orMongod x
  • 49. Targed Requests Shard Shard Shard Mongos 1 2 3 4
  • 50. Pall proceßing Shard Shard Shard Mongos 1 2 2 2 4 44 3 3 3 6 5
  • 51. What is a modn Web A?
  • 52. e g database to t your data
  • 53. e g database for YOUR dopmt
  • 54. e g Database for scale & Pfoance
  • 56. sy deploymt ๏ Heroku ๏ Rackspace ๏ Amazon ๏ Engine Yard ๏ App Fog ๏ ServerGrove ๏ Azure ๏ Nodejitsu
  • 57. Indust acaon ๏ Media & Entertainment ๏ Retail ๏ Social ๏ Finance ๏ Gaming ๏ Insurance ๏ Healthcare ๏ Government ๏ Archiving ๏ Telecom ๏ Education
  • 58. E IF YOU KED ! Questions? http://spf13.com http://github.com/spf13 @spf13 #DevCon5