Before joining Couchbase Phil has been a consultant on many different node.js and NoSQL projects working with many different languages and databases. By helping clients solve problems regarding scalability as well building completely new APIs he gained a broad knowledge of the available platforms and their tradeoffs in the big and small. He's a Developer Evangelist for Couchbase where he works to educate developers on the different parts of using a NoSQL database from mobile to big iron servers.
3. Couchbase 101
• Distributed
key-‐value
store
• Create
secondary
indexed
views
using
Map
Reduce
• AutomaBc
key-‐based
parBoning
• Integrated
memcached
caching
layer
• Strongly
consistent
within
a
cluster
• Cross-‐data
centre
replicaBon
• Intelligent
SDKs
4. Couchbase
Organiza1on
• Couchbase
operates
like
a
Key-‐Value
Document
Store
• Key
is
a
UTF-‐8
string
up
to
256
Bytes
• Values
can
be:
-‐ Simple
Datatypes:
strings,
numbers,
date1me,
boolean,
and
binary
data
can
be
stored
-‐-‐
they
are
stored
as
Base64
encoded
strings
-‐ Complex
Datatypes:
dic1onaries/hashes,
arrays/lists,
can
be
stored
in
JSON
format
(simple
lists
can
be
string
based
with
delimiter)
-‐ JSON
is
a
special
class
of
string
with
a
specific
format
for
encoding
simple
and
complex
data
structures
• Schema
is
unenforced
and
implicit,
schema
changes
are
programma1c,
done
online,
and
can
vary
from
Document
to
Document
5. Couchbase Server 2.0 Architecture
New
Persistence
Layer
storage
interface
Couchbase
EP
Engine
11210
Memcapable
2.0
Moxi
11211
Memcapable
1.0
Object-‐level
Cache
Disk
Persistence
8092
Query
API
Query
Engine
HTTP
8091
Erlang
port
mapper
4369
Distributed
Erlang
21100
-‐
21199
Heartbeat
Process
monitor
Global
singleton
supervisor
Configura1on
manager
on
each
node
Rebalance
orchestrator
Node
health
monitor
one
per
cluster
vBucket
state
and
replica1on
manager
h#p
REST
management
API/Web
UI
Erlang/OTP
Server/Cluster
Management
&
CommunicaBon
(Erlang)
RAM
Cache,
Indexing
&
Persistence
Management
(C)
6. Supported SDK's
www.couchbase.com/communiBes
• Each
supported
SDK
page
has
instruc1ons
for
setup
• PHP,
Ruby,
and
Python
clients
are
wrappers
around
libcouchbase
C
library,
so
libcouchbase
must
be
installed
first
• For
other
community
clients,
click
on
"All
Clients"
on
lea
nav,
scroll
down
the
page
and
you
can
see
clients
for
Go,
Erlang,
Clojure,
TCL,
Perl
and
others.
7. ‹#›Couchbase, Inc. Confidential
Easy Scalability
XDCR
Single Node
Type
No Manual Sharding
!
Database manages
data movement to
scale out -
Not the user
Database handles
propagation of
updates to scale
across clusters and
geos
!
Provides disaster
recover / data
locality
Hugely simplifies
management of
clusters
!
Easy to scale clusters
by adding any # of
nodes
FEATURES
Auto Sharding
Couchbase, Inc. Confidential
8. ‹#›Couchbase, Inc. Confidential
Consistent, High Performance
Fine
Grained
Locking
Built-in
Cache
Hash
Partitioning
Allows high
concurrency and
in turn high
throughput via
highly granular
latches
No need of
separate cache
layer
!
Database
manages
actively used
data
Uniform data
distribution
!
Uniform load
distribution –
NO hotspots
PERFORMANCE
Support a large
number of users
needed for
interactive apps
Massive
Concurrent
Connections
FEATURES
Couchbase, Inc. Confidential
9. ‹#›Couchbase, Inc. Confidential
Always on 24x7 Capability
All admin operations
online
!
•Compaction
•Indexing
•Rebalance
•Backup & Restore
•High availability using
in-memory replication
•Auto or manual
failover
•XDCR for disaster
recovery
Online
administrative
operations
HA via
Replication
DR via XDCR
FEATURES
Online DB upgrades
and HW maintenance
!
Optimized swap
operation to replace
nodes
Online DB
upgrades and
maintenance
Couchbase, Inc. Confidential
10. ‹#›Couchbase, Inc. Confidential
Flexible Data Model
Represent data as
objects instead of
shredding into rows
and columns
!
Create indexes on any
attribute of the
document
Each document can
have a different
structure
!
Easy to change data
without database
changes and downtime
Maintains Native
object
representation
Handles
constantly
changing data
JSON
JSON
JSON
JSONJSON
FEATURES
Data with mixed
structure better
managed via JSON in a
document DB than an
RDBMS
Schema-less for
structured / un/
semi- structured
data
Couchbase, Inc. Confidential
11. ‹#›Couchbase, Inc. ConfidentialCouchbase, Inc. Confidential
Couchbase Server Cluster
Basic Operation
User Configured Replica Count = 1
Read/write/update
Active
SERVER 1
Active
SERVER 2
Active
SERVER 3
App Server 1
COUCHBASE Client Library
!CLUSTER MAP
COUCHBASE Client Library
!CLUSTER MAP
App Server 2
Doc 5
Doc 2
Doc 9
Doc
Doc
Doc
Doc 4
Doc 7
Doc 8
Doc
Doc
Doc
Doc 1
Doc 3
Doc 6
Doc
Doc
Doc
Replica Replica Replica
Doc 4
Doc 1
Doc 8
Doc
Doc
Doc
Doc 6
Doc 3
Doc 2
Doc
Doc
Doc
Doc 7
Doc 9
Doc 5
Doc
Doc
Doc
• Docs distributed evenly across
servers
• Each server stores both active
and replica docs
Only one server active at a time
• Client library provides app with
simple interface to database
• Cluster map provides map
to which server doc is on
App never needs to know
• App reads, writes, updates docs
• Multiple app servers can access
same document at same time
12. ‹#›Couchbase, Inc. ConfidentialCouchbase, Inc. Confidential
Add Nodes to Cluster
SERVER 4 SERVER 5
Replica
Active
Replica
Active
Read/write/update
App Server 1
COUCHBASE Client Library
!CLUSTER MAP
COUCHBASE Client Library
!CLUSTER MAP
App Server 2
User Configured Replica Count = 1
Couchbase Server Cluster
Active
SERVER 1
Doc 5
Doc 2
Doc 9
Doc
Doc
Doc
Replica
Doc 4
Doc 1
Doc 8
Doc
Doc
Doc
Active
SERVER 2
Doc 4
Doc 7
Doc 8
Doc
Doc
Doc
Replica
Doc 6
Doc 3
Doc 2
Doc
Doc
Doc
Active
SERVER 3
Doc 1
Doc 3
Doc 6
Doc
Doc
Doc
Replica
Doc 7
Doc 9
Doc 5
Doc
Doc
Doc
Read/write/update
• Two servers added
with
one-click operation
• Docs automatically
rebalance across
cluster
Even distribution of
docs
Minimum doc
movement
• Cluster map updated
• App database
calls now distributed
over larger number
of servers
13. ‹#›Couchbase, Inc. ConfidentialCouchbase, Inc. Confidential
Fail Over Node
User Configured Replica Count = 1
SERVER 4 SERVER 5
Replica
Active
Replica
Active
App Server 1
COUCHBASE Client Library
!CLUSTER MAP
COUCHBASE Client Library
!CLUSTER MAP
App Server 2
Couchbase Server Cluster
Active
SERVER 1
Doc 5
Doc 2
Doc 9Doc
Doc
Doc
Replica
Doc 4
Doc 1
Doc 8Doc
Doc
Doc
Active
SERVER 2
Doc 4
Doc 7 Doc 8
Doc
Doc Doc
Replica
Doc 6
Doc 3 Doc 2
Doc
Doc Doc
Active
SERVER 3
Doc 1
Doc 3
Doc 6Doc
Doc
Doc
Replica
Doc 7
Doc 9
Doc 5Doc
Doc
Doc
• App servers accessing
docs
• Requests to Server 3
fail
• Cluster detects
server failed
– Promotes replicas of
docs to active
– Updates cluster map
• Requests for docs
now go to
appropriate server
• Typically rebalance
would follow
Doc 1 Doc 3
Doc
16. TradiBonal
Mobile
ApplicaBon
Server
REST
Services
Complex
Complex Sync
Code While Offline
or Cannot Use App
While Offline
Construction/
Deconstruction of
JSON
RDBMS Style
Local Storage
19. Couchbase
Lite
The
only
NoSQL
Database
for
Mobile
Devices
Couchbase*
Lite**
iOS*
Couchbase*
Lite**
Android*
Lite
Features
Ultra-‐lightweight,
secure
JSON
database
Na1ve
support
for
iOS,
Android
and
REST/HTML5
Powerful
conflict
resolu1on
Automated
Sync
20. Couchbase
Lite
The
only
NoSQL
Database
for
Mobile
Devices
Couchbase*
Lite**
iOS*
Couchbase*
Lite**
Android*
Lite
Features
Ultra-‐lightweight,
secure
JSON
database
Na1ve
support
for
iOS,
Android
and
REST/HTML5
Powerful
conflict
resolu1on
Automated
Sync
21. Couchbase
Lite
Features
• Use
JSON
in
your
Mobile
App
Data
Tier
• Always
Work
with
Local
Data
on
Device
• Modify
schema
dynamically,
super
flexible
• When
Connected:
Create
New
Data
and
Change
Documents,
they
Sync
AutomaBcally
• When
Not
Connected:
Work
with
solid
local
NoSQL
database
• Powerful
conflict
resoluBon
features
26. So what can we do
• Handle
user
authenBcaBon
• Handle
document
channels
• Synchronise
mulBple
devices
/
applicaBons
27. channel()
Channels
organize
what
JSON
Documents
are
synchronized
down
to
which
Users
User
A
User
B
User
C
JSON
doc.channels
:
“food”
JSON
doc.channels
:
[
“food”,
“sports”
]
JSON
doc.channels
:
[
“sports”,
“travel”
]
channels:
food
channels:
sports
channels:
food,
travel
User
D
creates
Content
with
Channel
associaBon
These
Users
Subscribed
to
Content
Channels