Download - NoSQL Databases
![Page 1: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/1.jpg)
NoSQL Databases
Cloudant & Redis
Nikolay TomitovTechnical TrainerSoftAcad Training Center
![Page 2: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/2.jpg)
www.softacad.bg
Schema-free Databases
Documental Databases Relational Databases
![Page 3: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/3.jpg)
JSON Data Format
www.softacad.bg
![Page 4: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/4.jpg)
Meet Cloudant
www.softacad.bg
Cloudant == managed installation of Apache CouchDB in the cloud
![Page 5: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/5.jpg)
Cloudant scales within & between data centers◦ Global networks of servers◦ Built-in replication and sync◦ Push the data closer to the user & application◦ Disaster recovery
Global Data Network
www.softacad.bg
![Page 6: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/6.jpg)
Eliminates data layer-related complexity, delay, cost, and risk
Performance & scale with no worries Build epic apps, easily
◦ Enables advanced app features and analytics◦ Full-text search, off-line computing, replication,
incremental MapReduce, code and data◦ distribution...◦ Accelerates release cycles (reduces time to
value) Start for free, pay as you grow
Nice Features
www.softacad.bg
![Page 7: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/7.jpg)
www.softacad.bg
Provision Signup is free, and access is immediate
Define No schema, usually just JSON Access RESTful API View Define data views via Javascript Search Integrated, Lucene-like full-text search Analyze Incremental, chainable MapReduce Operate Dashboards to monitor, compact,
replicate Grow Automatic
Developingwith Cloudant
![Page 8: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/8.jpg)
Data is stored and returned in JSON format
Queried via HTTP RESTful API
Index building language: Javascript
Simple and intuitive interface
CouchDB Inside
www.softacad.bg
![Page 9: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/9.jpg)
• Create:HTTP PUT /db/test
• Read:HTTP GET /db/test
• Update:HTTP PUT /db/test
• Delete:HTTP DELETE /db/test
REST Interface – DEMO
www.softacad.bg
![Page 10: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/10.jpg)
Views: the way to arrange data to answer our questions
Method to build views:Incremental MapReduce using
JavaScript
Querying the DB
www.softacad.bg
![Page 11: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/11.jpg)
DEMO – Simple MapReduce
www.softacad.bg
![Page 12: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/12.jpg)
Example
www.softacad.bg
![Page 13: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/13.jpg)
How to Findsum(checkouts) ?
www.softacad.bg
![Page 14: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/14.jpg)
Simple Map: emit(checkout)
www.softacad.bg
![Page 15: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/15.jpg)
Simple Reduce: sum(checkouts)
www.softacad.bg
![Page 16: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/16.jpg)
Simple Reduce: sum(checkouts)
www.softacad.bg
![Page 17: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/17.jpg)
Views can be Distributed
www.softacad.bg
![Page 18: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/18.jpg)
Practice Map Reduce at:
http://blog.mudynamics.com/wp-content/uploads/2009/04/icouch.html
http://couchdb.apache.org/downloads.html
Practice
www.softacad.bg
![Page 19: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/19.jpg)
Meet Redis
“Redis is an open source, advanced key-value storeIt is often referred to as a data structure server Since keys can contain strings, hashes, lists, sets and sorted sets
www.softacad.bg
![Page 20: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/20.jpg)
www.softacad.bg
Features First It’s really fast
◦Non-blocking I/O, single threaded◦100,000+ read/writes a second
It complements yourexisting storage layer
It is very feasible for small apps
But..trade performance for durabilitywww.softacad.bg
![Page 21: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/21.jpg)
www.softacad.bg
Short keys perform better
Could not contain whitespaces
Common convention is : obj-type:id:field◦user:77:pass = abcd
SHA1(data) makes a useful key too
Keys
![Page 22: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/22.jpg)
www.softacad.bg
strings (up to 1GB) Lists of strings Sets of strings Sorted sets Hashes Pubsub channels
Supported Data Types
![Page 23: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/23.jpg)
www.softacad.bg
EXISTS[key] DEL[key] TYPE[key] RENAMENX[key] EXPIRE [key] EXPIREAT[key] TTL[key]
Commands on All Keys
![Page 24: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/24.jpg)
www.softacad.bg
SET[key value]
MGET[key1 key2 key3..]
GET [key]
INCR/DECR [key]
INCRBY/DECRBY[key]
Commands on Strings
![Page 25: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/25.jpg)
www.softacad.bg
Store session data + creation time
Hit counts◦ key =MD5(url)◦ Incr hits-by-key:$key
APPEND can be used for logging
Redis as shared memory location
Progress bars, polling
Common Uses
![Page 26: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/26.jpg)
www.softacad.bg
More durability -> less performance
Default behaviour fork-and-save a snapshot to disk every…◦15 mins if one key has changed◦5 mins if 10 keys have changed◦60 secs if 10000 keys have changed
SAVE/BGSAVE commands trigger a save
Durability
![Page 27: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/27.jpg)
www.softacad.bg
DEMO (JAVA)
![Page 28: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/28.jpg)
Try it :◦ http://try.redis-db.com
Redis Admin UI◦ http://www.servicestack.net/mythz_blog/?p=381
Check It Out
www.softacad.bg
![Page 29: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/29.jpg)
Amazon SimpleDB
![Page 30: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/30.jpg)
www.softacad.bg
Non–relational data store Designed to be highly available and flexible
Available only on Amazon WS
SimpleDB: Overview
![Page 31: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/31.jpg)
www.softacad.bg
Low touch – almost no administration needed
Highly available – automatic replication and fail over
Flexible – not bound by a schema Simple to use – supports only the most
common operations Designed for integration with other
Amazon Web Services Secure RESTful interface
SimpleDB: Functionality
![Page 32: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/32.jpg)
www.softacad.bg
Free tier – 1 GB/month, 25 SimpleDB machine hours
Only outgoing transfers are charged Data transfers in the same region are free
Monthly rates between $0.12 and $0.05
SimpleDB: Pricing
![Page 33: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/33.jpg)
www.softacad.bg
Optimized reads and writes Easily integrated with other AWS Uses the HTTP protocol for communication
Ideal for storing non – structured or semi – structured data
SimpleDB: Pros
![Page 34: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/34.jpg)
www.softacad.bg
Limited functionality compared to relational and other non – relational products
Complex queries need a lot of coding No fulltext indexing All queries have the N + 1 problem
SimpleDB: Cons
![Page 35: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/35.jpg)
DemoAmazon Simple DB
![Page 36: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/36.jpg)
Google Datastore (GDS)
![Page 37: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/37.jpg)
www.softacad.bg
Schemaless object datastore Designed to scale Hierarchical Available only on Google App Engine
GDS: Overview
![Page 38: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/38.jpg)
www.softacad.bg
No administration needed Flexible – not bound by a schema Designed for no downtime Automatic replication Queries must run against predefined
indexes Rich query engine Atomic transactions APIs available for all the languages
supported by GAE
GDS: Functionality
![Page 39: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/39.jpg)
www.softacad.bg
Free quota: 1GB, 200 indexes Monthly rates: $0.24/gigabyte; between $0.01 and $0.10 for 100k database operations
GDS: Pricing
![Page 40: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/40.jpg)
www.softacad.bg
Fast Hierarchical queries boost speed Atomic transactions supported Large and active community The Java API include implementations of JDO and JPA
GDS: Pros
![Page 41: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/41.jpg)
www.softacad.bg
Limited functionality◦Compared to relational databases and
other non–relational data stores Indexes require additional configuration
GDS: Cons
![Page 42: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/42.jpg)
DemoGoogle App Engine Datastore
![Page 43: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/43.jpg)
MongoDB
![Page 44: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/44.jpg)
www.softacad.bg
Non – relational, schema free database
Highly scalable Engineered for maximum speed Available as a stand alone product A number of hosted MongoDB solutions available◦MongoLab◦MongoHQ◦Mongo Machine
Overview
![Page 45: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/45.jpg)
www.softacad.bg
Almost administration free High availability – replication and sharding A rich set of features
◦ Complex queries◦ Aggregate functions◦ Map/Reduce operations◦ Indexes◦ Stored procedures◦ BLOB storage (GridFS)
Database drivers available for a large list of programming languages
MongoDB: Functionality
![Page 46: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/46.jpg)
MongoDB:Hosted Solutions
MongoLab MongoHQ
Easy setup (No billing info needed)
Intuitive interface 240MB free Deploy on Amazon
EC2, Rackspace or Joynet
MongoDB Version 1.8
Easy setup (Credit card needed)
Intuitive interface 16MB free Deploy only on
Amazon EC2 Different MongoDB
Version according to price plan
![Page 47: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/47.jpg)
www.softacad.bg
Fast Rich feature set Mature product Large and active community
MongoDB: Pros
![Page 48: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/48.jpg)
www.softacad.bg
No relational database style transactions
No data validation
MongoDB: Cons
![Page 49: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/49.jpg)
DemoMongoDB on MongoLab
![Page 50: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/50.jpg)
www.softacad.bg
1. Register for a free Cloudant account at https://cloudant.com.
2. Write a simple "Dictionary" application in Java, C#, PHP, or JavaScript to perform the following in Cloudant:
◦ Add a dictionary entry (word + translation)◦ List all words and their translations◦ Find the translation of given wordThe UI of the application is up to you (it could be Web-based, GUI or console-based).You may download a Cloudant client library from http://wiki.apache.org/couchdb/Related_Projects
Homework
![Page 51: NoSQL Databases](https://reader034.vdocument.in/reader034/viewer/2022052209/56814b54550346895db84cc1/html5/thumbnails/51.jpg)
www.softacad.bg
3. Implement the previous task ("Dictionary") with Redis
◦ Register for a free "Redis To Go" account at: https://redistogo.com
◦ Download the client libraries for your favorite programming language from http://redis.io/clients
4. Implement the previous task ("Dictionary") with MongoDB (register at MongoLab or MongoHQ)
5. Optionally (if you want) implement the previous task ("Dictionary") with Google Datastore or Amazon SimpleDB
Homework (2)