CloudAnt: Database as a Service (DBaaS) Some Basic Idea to start with cloudant development Mansura Habiba
Agenda Different Components of Cloudant Document Structure for Cloudant Single Big Document Concept Map/ Reduce in Cloudnat Implement 1:m relation without Big single document Some SQL Aggregate functions Replication Consistancy Management in CloudAnt Attachment(s) to document
Different Component of cloudant Architecture It Provides fundamental component for DBaaS
Document Structure for Cloudant Documents are stored as Json Documents and View can be accessed through API The One single document for all related information for the an Entity 1:m Relation in a single document
Single Big Document Concept The Concept is - all child document will be inside the parent document as array. Such as comments in this example Why not recommnded usually? Very long document Complex structure HTTP 409 conflict error if multiple client process start editing same document. E.g in this example multiple client start adding comment to the same blog post , the single document might return 409 Too much redandancy blog comments { "_id": “user01", “name": “…", "author": "john", "title": "My blog post", "content": "Bla bla bla …", "comments": [ {"author": "jack", "content": "…"}, {"author": "jane", "content": "…"} ] } Is this a good idea? It can be, if: Not to big document and performance is manageable by using views. The information in the inner document only appears there and does not need to be duplicated into other documents, or such duplication is acceptable for your application. For example, if you wanted to rename the "couchdb" skill to "couchdb / cloudant", you would have to update it in all employee documents. The document does not get updated concurrently. If it does, there will likely be unnecessary conflicts that will need to be resolved by the application. It is called “The everything-in-one-document approach”
Map/Reduce in Cloudant “MapReduce is a software framework introduced by Google to support distributed computing on large data sets on clusters of computers.” Used by cloudant to implement views Just a framework / pattern: You can implement “any” algorithm using map-reduce. Map and reduce functions are custom .Specially its just similar to the query in relational database in order to create a view Reduce is optional, plain view serves as a document index
Map /Reduce in Cloudant (Cont...)
Using Map/Reduce to implement 1:m relation without Big single document (1/3) Use case: A number of student have different courses from a number of courses Relation : 1 course: m students Query: list of students who has registered for course_1 For Example, Student 030206 and 030208 have been registered for course 1
List of students who have registered for course_1 Using Map/Reduce to implement 1:m relation without Big single document (3/3) List of students who have registered for course_1
How to Link Document in Cloudant There is no ensured inter document consistency in cloudant List IDs of related documents in document (1:m) one document contains the ids of other documents
Using Map/Reduce to implement 1:m relation without Big single document (2/3) Map/Reduce function to achieve the goal Query to achieve the goal
Some SQL Aggregate functions using cloudant Map/Reduce (1/5) Count: How many course a student has been registered against
Some SQL Aggregate functions using cloudant Map/Reduce (2/5) sum : The total marks that 030206 obtain in different courses
Some SQL Aggregate functions using cloudant Map/Reduce (3/5) avg: The average marks that 030206 obtain in different courses Reduce Function Map Function
Some SQL Aggregate functions using cloudant Map/Reduce (3/5 cont...)
Some SQL Aggregate functions using cloudant Map/Reduce (4/5) max: The maximum marks that 030206 obtain among all courses Reduce Function Map Function
Some SQL Aggregate functions using cloudant Map/Reduce (5/5) min: The minimum marks that 030206 obtain among all courses Map Function Reduce Function
Replication Consistancy Management in CloudAnt eventually consistent If the application performs a document write or update, followed immediately by a read of the same document, older document content is retrieved. Only the leader are allowed for data write operation, Replica nodes replicate data from the leader leader replica Replicas = # of nodes storing replica Writes = # of nodes that confirm a commit Reads= # of nodes that are contacted at a read operation Strongly consistent Writes + Reads > Replicas replica replica Cloudant is eventually consistent rather than strongly consistent.
Attachment(s) to document Single inline attachment Multiple inline attachment If ?attachments=true is added to the query , it will return resulted documents along with attachments Elastic search has an implementation for creating search index in attachment but I am afraid that’s not an option for CDP
Reference https://docs.cloudant.com/api.html http://www.slideshare.net/cindyrussell129357/develop-mobile-and- internet-connected-apps-with-db2-and-informix-cover http://www.slideshare.net/AnimeshSingh/buils-scalable-internet-of- things-apps-bluemix-cloudant-for-designing-iot-apps
Some libraries to access cloudant API for development https://docs.cloudant.com/libraries.html#objective-c-and-swift https://docs.cloudant.com/libraries.html#python https://docs.cloudant.com/libraries.html#couchdb https://docs.cloudant.com/libraries.html#node.js https://docs.cloudant.com/libraries.html#java https://docs.cloudant.com/libraries.html#mobile Cloudant is also available as an IBM Bluemix service