Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Scalability	of	NoSQL.	Flexibility	of	JSON.	Power	of	SQL.
Vu	Nguyen
What	is	Couchbase?
Couchbase Server Couchbase Mobile
• Document	Database
• Key/Value	Store
• Distributed	Cache
• Embedded	...
Data	in	Couchbase
• Key:	“DocumentID”
• Any	string	up	to	250	bytes
• Unique	inside	a	bucket
• Value
• Any	value	up	to	20	M...
Architecture
• Node
A	Couchbase instance.
Architecture
• Node
A	Couchbase instance.
• Cluster
A	scalable,	networked	set	of	nodes.
Architecture
• Node
A	Couchbase instance.
• Cluster
A	scalable,	networked	set	of	nodes.
• Bucket
A	logical	collection	of	d...
Architecture
• Node
A	Couchbase instance
• Cluster
A	scalable,	networked	set	of	nodes
• Bucket
A	logical	collection	of	doc...
How	to	access	data?
1. Read/write	documents	by	their	keys
• Extremely	fast	due	to	cache
2. Map	Reduce	views
• Distributed	...
Single-Node	Architecture
Cluster	Manager
Data	Service
Index	Service
Query	Service
Managed	Cache
Storage
Couchbase Server	n...
Cluster	Architecture
Cluster	Manager
Data	Service
Index	Service
Query	Service
Managed	Cache
Storage
Cluster	Manager
Data	S...
How	does	a	get operate?
Data	Service
Managed	Cache
Storage
doc	2 doc	3
doc	1 doc	2 doc	3 doc	4
doc	2 doc	4
Replication	
qu...
How	does	a	set operate?
Data	Service
Managed	Cache
Storage
doc	4
doc	1 doc	2 doc	3 doc	4
doc	4
Replication	
queue
Persiste...
Why	Couchbase server	fast?
• Get	and	set	are	served	primarily	from	cache
• Disk	writes	are	append	only
doc	1 doc	2 doc	3
Why	Couchbase server	fast?
• Get	and	set	are	served	primarily	from	cache
• Disk	writes	are	append	only
doc	1 doc	2 doc	3 d...
Why	Couchbase server	fast?
• Get	and	set	are	served	primarily	from	cache
• Disk	writes	are	append	only
doc	1 doc	2 doc	3 d...
Why	Couchbase server	fast?
• Get	and	set	are	served	primarily	from	cache
• Disk	writes	are	append	only
• Data	files	are	pe...
Why	Couchbase server	fast?
• Get	and	set	are	served	primarily	from	cache
• Disk	writes	are	append	only
• Data	files	are	pe...
Map	Reduce
Views	are	secondary	indexes
• Written	in	JavaScript
• Executed	by	V8	engine
function (doc, meta) {
if (doc.age ...
N1QL	Queries
SQL	for	JSON	data
• SELECT, INSERT, UPDATE, DELETE
• JOIN, WHERE, GROUP BY
• CREATE INDEX, DROP INDEX
• MIN, ...
Bucket	&	vBucket
• Each	bucket	is	divided	into	1024	vBucket.
• vBuckets are	distributed	evenly	across	all	nodes
in	the	clu...
Couchbase Mobile
• Embedded	database	for	iOS	&	Android
• Unofficial	JavaScript	database	(browser	&	NodeJs)
• Real-time	syn...
Architecture
CouchDB protocol
GET	/source/_changes?feed=normal&style=all_docs&heartbeat=10000
{
"results":[
{"seq":14,"id":"f957f41e","...
Sync	Function
function (doc, oldDoc) {
if (doc._deleted) {
requireRole("role:editor");
requireUser(oldDoc.writers);
return...
Scalability	of	NoSQL.	Flexibility	of	JSON.	Power	of	SQL.
Vu	Nguyen
Upcoming SlideShare
Loading in …5
×

TechTalk #14 Grokking: Couchbase - NoSQL + Memcached + Real-time + Offline!

945 views

Published on

You may want a NoSQL database for your project? And a memcached for speed things up? Or you may want an offline and real-time database which is ready for your mobile apps? MongoDB or Redis or Firebase? Let's try Couchbase!

Speaker: Vu Nguyen - Web Freelancer

Vu Nguyen is a young and passionate engineer. Previously he founded Liti Book, the next generation of productivity tool which is support more collaboration.

Published in: Technology
  • Be the first to comment

TechTalk #14 Grokking: Couchbase - NoSQL + Memcached + Real-time + Offline!

  1. 1. Scalability of NoSQL. Flexibility of JSON. Power of SQL. Vu Nguyen
  2. 2. What is Couchbase? Couchbase Server Couchbase Mobile • Document Database • Key/Value Store • Distributed Cache • Embedded Database • Offline & Real-time sync
  3. 3. Data in Couchbase • Key: “DocumentID” • Any string up to 250 bytes • Unique inside a bucket • Value • Any value up to 20 MB • Any thing: JSON, XML, serialized object, string, etc. • Meta data • CAS (check-and-set) • TTL (time-to-live) • Optional flags
  4. 4. Architecture • Node A Couchbase instance.
  5. 5. Architecture • Node A Couchbase instance. • Cluster A scalable, networked set of nodes.
  6. 6. Architecture • Node A Couchbase instance. • Cluster A scalable, networked set of nodes. • Bucket A logical collection of documents with unique keys. Buckets are evenly distributed across a cluster. [key1: value] [key2: value] [key3: value] [key4: value] [key5: value] [key6: value]
  7. 7. Architecture • Node A Couchbase instance • Cluster A scalable, networked set of nodes • Bucket A logical collection of documents with unique keys. Buckets are evenly distributed across a cluster. • Document A key/value pair within a bucket. Keys are unique within a bucket. [key1: value] [key2: value] [key1: value] [key2: value] [key3: value] [key4: value] [key3: value] [key4: value] [key5: value] [key6: value] [key5: value] [key6: value]
  8. 8. How to access data? 1. Read/write documents by their keys • Extremely fast due to cache 2. Map Reduce views • Distributed secondary indexes, built using map-reduce 3. N1QL (“nickel”) query • SQL superset for indexing and querying JSON structure 4. Full text search • Couchbase FTS
  9. 9. Single-Node Architecture Cluster Manager Data Service Index Service Query Service Managed Cache Storage Couchbase Server nodes are identical. Two core components - Cluster Manager - Node Managers Three independent services - Data Service - Index Service - Query Service
  10. 10. Cluster Architecture Cluster Manager Data Service Index Service Query Service Managed Cache Storage Cluster Manager Data Service Index Service Query Service Managed Cache Storage Cluster Manager Data Service Index Service Query Service Managed Cache Storage Cluster Manager Data Service Index Service Query Service Managed Cache Storage Cluster
  11. 11. How does a get operate? Data Service Managed Cache Storage doc 2 doc 3 doc 1 doc 2 doc 3 doc 4 doc 2 doc 4 Replication queue Persistence queue Get is extremely fast: - Common docs are cached - Binary TCP connection Two configs: - Value-only ejection - Full meta-data ejection
  12. 12. How does a set operate? Data Service Managed Cache Storage doc 4 doc 1 doc 2 doc 3 doc 4 doc 4 Replication queue Persistence queue Acknowledge type: - When in RAM (default) - When in storage - When replicated Replication - Very fast, RAM to RAM
  13. 13. Why Couchbase server fast? • Get and set are served primarily from cache • Disk writes are append only doc 1 doc 2 doc 3
  14. 14. Why Couchbase server fast? • Get and set are served primarily from cache • Disk writes are append only doc 1 doc 2 doc 3 doc 1
  15. 15. Why Couchbase server fast? • Get and set are served primarily from cache • Disk writes are append only doc 1 doc 2 doc 3 doc 1 doc 3
  16. 16. Why Couchbase server fast? • Get and set are served primarily from cache • Disk writes are append only • Data files are periodically compressed doc 2 doc 1 doc 3doc 1 doc 3
  17. 17. Why Couchbase server fast? • Get and set are served primarily from cache • Disk writes are append only • Data files are periodically compressed doc 2 doc 1 doc 3
  18. 18. Map Reduce Views are secondary indexes • Written in JavaScript • Executed by V8 engine function (doc, meta) { if (doc.age > 30) { emit(doc.department, null) } }
  19. 19. N1QL Queries SQL for JSON data • SELECT, INSERT, UPDATE, DELETE • JOIN, WHERE, GROUP BY • CREATE INDEX, DROP INDEX • MIN, MAX, COUNT • UNION, INTERSECT, EXCEPT, ... SELECT count(*), city FROM customer WHERE customer.type = “vip” GROUP BY customer.city ORDER BY customer.city LIMIT 5 OFFSET 5
  20. 20. Bucket & vBucket • Each bucket is divided into 1024 vBucket. • vBuckets are distributed evenly across all nodes in the cluster. • As nodes join/leave cluster, vBuckets adjust automatically. Active vBuckets Replicated vBuckets Active vBuckets Replicated vBuckets Active vBuckets Replicated vBuckets
  21. 21. Couchbase Mobile • Embedded database for iOS & Android • Unofficial JavaScript database (browser & NodeJs) • Real-time synchronization • CouchDB replication protocol
  22. 22. Architecture
  23. 23. CouchDB protocol GET /source/_changes?feed=normal&style=all_docs&heartbeat=10000 { "results":[ {"seq":14,"id":"f957f41e","changes":[{"rev":"3-46a3"}],"deleted":true}, {"seq":29,"id":"ddf339dd","changes":[{"rev":"10-304b"}], ], "last_req": 78, } GET /source/_changes?feed=continuous&style=all_docs&heartbeat=10000 {"seq":14,"id":"f957f41e","changes":[{"rev":"3-46a3"}],"deleted":true} {"seq":29,"id":"ddf339dd","changes":[{"rev":"10-304b"}]
  24. 24. Sync Function function (doc, oldDoc) { if (doc._deleted) { requireRole("role:editor"); requireUser(oldDoc.writers); return; } if (!doc.title || !doc.creator || !doc.channels || !doc.writers) { throw({forbidden: "Missing required properties"}); } else if (doc.writers.length == 0) { throw({forbidden: "No writers"}); } if (oldDoc == null) { requireRole("role:editor"); requireUser(doc.creator) } else { requireUser(oldDoc.writers); if (doc.creator != oldDoc.creator) { throw({forbidden: "Can't change creator"}); } } channel(doc.channels); }
  25. 25. Scalability of NoSQL. Flexibility of JSON. Power of SQL. Vu Nguyen

×