Tuesday 4 February 2014

CouchBaseNoSQL

CouchBase is a Key-Value NoSQL database which store data in the form of JSON document. To understand couchbase database we need to keep SQL concepts a bit aside, it will really be helpful. It has a flexible data model, is easily scalable, provides consistent high performance and is “always-on,” meaning it is can serve application data 24 hours, 7 days a week. The other great thing about CouchBase is that you can easily distribute your data across N+ 1 node simply by adding new CouchBase nodes to your cluster.


Understanding CouchbaseConcepts:

Couchbase as Document Store: The primary unit of data storage in Couchbase Server 2.0 is a JSON document, which is a data structure capable of holding arrays and other complex information. By using JSON documents to model your data, you can construct your application data as individual documents.Because you model your application objects as documents, you do not need to perform schema migrations. The documents you use and the fields they store will indicate any relationships between application objects, therefore to update the structure of objects you store, you merely change the document structure that you write to Couchbase Server.

Data Buckets: Your web application stores data in a Couchbase cluster using buckets. Buckets are isolated, virtual containers which logically group records within a cluster; they are the functional equivalent to a database. Buckets can be accessed by multiple client applications across a cluster. They provide a secure mechanism for organizing, managing and analysing data storage. As an application developer you will most likely create buckets for your development and production environment.

Keys and Metadata: All information that you store in Couchbase Server are documents with keys. Keys are unique identifiers for a document, and values are either JSON documents or if you choose the data you want to store can be byte stream, data types, or other forms of serialized objects.Keys are also known as document IDs and serve the same function as a SQL primary key. A key in Couchbase Server can be any string, including strings with separators and identifiers, such as ‘person_93679.’ A key is unique.By default, all documents contain three types of metadata which are provided by the Couchbase Server. This information is stored with the document and is used to change how the document is handled.

Couchbase SDKs: A Couchbase SDK is responsible for communicating with the Couchbase Server and provides language-specific interfaces your web application can use to perform database operations.All Couchbase SDKs automatically read and write data to the right node in a cluster. If database topology changes, the SDK responds automatically and correctly distribute read/write requests to the right cluster nodes. The following shows a single web application server, the Couchbase SDK, and a Couchbase Server cluster. In real deployments, multiple web application servers can communicate via a Couchbase SDK to a cluster.

+

Nodes and Clusters
You deliver your application on several grouped servers, also known as a cluster. Each cluster consists of multiple nodes :
  • Couchbase Server or Node: A node is a single instance of a Couchbase Server running on a physical or virtual machine, or other environment.
  • Cluster: This is a collection of one or more nodes. All nodes in a cluster are identical in function, interfaces, components and systems. Couchbase Server manages data across nodes in a cluster. When you increase the size of a cluster, the cluster scales linearly, there is no hierarchy or parent/child relationshipbetween multiple nodes in a cluster.
Nodes or clusters typically reside on a separate physical machine than your web server.

Benifits
Couchbase Server is well suited for the issues faced when you use a traditional RDBMS:
  • Stores many serialized objects,
  • Stores dissimilar objects that do not fit a single schema,
  • Scales out from thousands to millions of users rapidly,
  • Performs large volume reads/writes,
  • Supports schema and application data changes on running system.
If you need a system that provides a high level of scalability, flexibility in data structure, and high performance, a NoSQL solution such as Couchbase is well suited.

Following example explains you how class structure gets represented in JSON structure.

//Sample of Class structure:

publicclassFact
    {
publicstring QID { get; set; }

publicIList<string> FileType { get; set; }

publicFDetails FDetails { get; set; }

publicDateTime TS { get; set; }

publicbool IsDel { get; set; }

    }

//Sample of JSON structures:
Fact.00AAATest.WIP
{
  "QID": "003746",
"FileType": [
    "TxnyD.AllowedFileFormats.2.2",
    "TxnyD.AllowedFileFormats.4.2"
  ],
  "FDetails": {
"ST": [
      "TxnyD.Topic.1.1_TxnyD.Subtopic.1.2"
    ],
    "IsVariable": {
      "False": null
    },
    "BNar": "Loc.33217",
    "SNar": "Loc.33217",
    "HNar": "Loc.33217",
    "CNar": "Loc.33217",
    "TNar": "Loc.33217",
    "IsCountrySpecific": {
      "False": null
    },
    "Provenience": null,
    "IsShared": false,
    "IsGlobal": null,
    "SectorSpecific": null,
    "CustomerSpecific": null
  },
  "TS": "0001-01-01T00:00:00",
  "IsDel": false
}

About Author:
Akansha Patil  is enthusiast .net developer who works as associate consultant with Systems Plus Pvt. Ltd. She in free time reads and write on various web technologies. She can be contacted at: aakanksha.patil@spluspl.com

3 comments: