Tuesday, February 18, 2014

The Arrival of NoSQL

In business system analysis one of the main part is how system data being store, retrieve and manipulate to business operations. End result of this process is create the schema for the business system. This schema consist with collection of relation tables and views. But in this relational database model its own limitation and drawbacks. We can list down some of factors as in below.
  • Relational database model can take long time to perform complete data analysis and design schema. In business user expect their system quickly up and running. 
  • Relational database design consist with tables and developers should access it using SQL. But business logic develop through objects and methods. So overcome this mismatch between database model and programming model, we have to use ORM like Entity Framework.
  • Relational databases are very difficult to modify if more application depends on it. If change one place it can effect to the many place in the business application.
  • In some scenarios relational database not able show all business requirement relationship. 
  • Many high end relational database systems more expensive when going for a scalability and high - availability. And also licencing cost for the product.  
To address these limitation of flexibility, availability, Performance and scalability which has in relational database brought NoSQL database to the table.  In other words "Non - Relational Database". NoSQL databases categorize  into a small set of functional areas: key/value stores, document databases, column-family databases, and graph databases.  

Key/Value stores

A key/value store implements simplest of the NoSQL storage mechanismsl. A key/value store is large hash table. Each data value associate with a unique key, and the key/value store uses this key to determine where to store the data in the database by using an appropriate hashing function. The hashing function is selected to provide an even distribution of hashed keys across data storage. 


Document Databases

A document database is similar in concept to a key/value store except that the values stored are documents. A document is a collection of named fields and values, each of which could be simple scalar items or compound elements such as lists and child documents. The data in the fields in a document can be encoded in a variety of ways, including XML, YAML, JSON, BSON, or even stored as plain text.

Column-family Database

A column-family database store its data into rows and columns, and in its simplest form a column-family database can appear very similar to a relational database, at least conceptually. The real power of a column-family database lies in its denormalized approach to structuring sparse data.

Graph Databases

Same like other categories of NoSQL databases, a graph database enables to store entities, but the main focus is on the relationships that these entities have with each other. A graph database stores two types of information; 
  • Nodes which is instances of entities 
  • Edges which specify the relationships between nodes. 
Nodes and edges can both have properties that provide information about that node or edge just like columns in a table. Edges can have a direction indicating the nature of the relationship. The purpose of a graph database is to enable an application to efficiently perform queries that traverse the network of nodes and edges, and to analyse the relationships between entities. 

Wednesday, February 12, 2014

Threading to JavaScript 3



The second post of this article series shows small application with web worker. This post going to shows web worker with JSON. Please refer first post and second post.

Following shows main page HTML structure. Main page has three buttons with respective onclick event handler. One button for send JSON data to the web worker, another button for get JSON data from web worker and third button for terminate web worker from JSON message.

Web worker demo

Following shows main page JavaScript code. First part of this code contain implementation for start web worker and it contain with onmessage event listener for web worker object. After that it has implementation of onclick event handler in each buttons. Inside those methods create JSON object to send web worker. 

Following shows doWebWorker.js file implementation. Inside the switch statement check JSON object. For Get request create new JSON object and send back to the main page.

var message;
that = this;
self.addEventListener('message', function (e) { 
 
 var data = e.data;
 switch (data.cmd) {
  case 'send':
   that.sendMessage('WORKER RECEIVED JSON DATA: ' + data.msg);
   break;
  case 'get':
   var val = {
    'cmd': 'WORKER SEND JSON DATA',
    'msg': 'worker said hi !'
   }
   that.sendMessage(val);
   break;
  default:
   that.sendMessage('WORKER STOPPED: ' + data.msg);
   // Terminates the worker.
   that.terminatesWorker();
 };
}, false);

function sendMessage(message)
{
 self.postMessage(message);
}

function terminatesWorker() {
 self.close();
}

Final result looks like shown in below.


Result of Send Json button click

Result of Get Json button click

Result of Stop Worker button click