Couchbase in the Enterprise with Spring Data and Hibernate OGM
I gave this talk at ConFESS 2013 (https://2013.con-fess.com/). It contains both the introduction to Couchbase Server 2.0, how to work with the Java SDK and how the current state of Spring Data & Hibernate OGM integration is.
NoSQL database projects focused on distributed database technology and surrounding ecosystem • Supports both key-‐value and document-‐oriented use cases • All components are available under the Apache 2.0 Public License • Obtained as packaged soSware in both enterprise and community ediCons.
On 24x365 Grow cluster without applicaCon changes, without downCme with a single click Consistent sub-‐millisecond read and write response Cmes with consistent high throughput No downCme for soSware upgrades, hardware maintenance, etc. JSON JSON JSON JSON JSON PERFORMANCE Flexible Data Model JSON document model with no fixed schema. Core Principles
Global singleton supervisor ConfiguraCon manager on each node Rebalance orchestrator Node health monitor one per cluster vBucket state and replicaCon manager hdp REST management API/Web UI HTTP 8091 Erlang port mapper 4369 Distributed Erlang 21100 -‐ 21199 Erlang/OTP storage interface Couchbase EP Engine 11210 Memcapable 2.0 Moxi 11211 Memcapable 1.0 Memcached New Persistence Layer 8092 Query API Query Engine Data Manager Cluster Manager
Single node -‐ Couchbase Read Operacon Disk Queue ReplicaCon Queue App Server Doc 1 Doc 1 Doc 1 Managed Cache Disk To other node Couchbase Server Node
distributed evenly across servers • Each server stores both accve and replica docs Only one server acCve at a Cme • 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 • Mulcple app servers can access same document at same cme User Configured Replica Count = 1 READ/WRITE/UPDATE ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9
it • Keys must be max. 255 UTF-‐8 chars long must be unique in a bucket (“database”) are completely under the control of the applicaCon • Values can be any binary blob (but bonus points when JSON!) can be up to 20MB in size
a document • set(key, value) Store a document or replace if it exists • add(key, value) Store a document and fail if it exists • replace(key, value) Replace a document and fail if it does not exist
lightweight format to represent document structure in a language-‐independent manner. • If JSON documents are stored, the View engine can be used. • Allows to build secondary indexes on your datasets. • Makes it possible to ask quesCons like “Give me all user documents by lastname”.
to avoid hilng the database as much as possible. Use JOINs and let the DB opCmizer figure out what to do • In Couchbase, get’s and set‘s are so fast they are trivial, not boglenecks, this is hard for many people to accept at first; Mulcple get statements are commonplace, don’t avoid it!
“flags”: 0, “expiraCon”: 0, “type”: “json” } document { “uid”: 123456, “firstname”: “Michael”, “lastname”: “Nitschinger”, “age”: 25, “favorite_colors”: [“blue”, “black”], “email”: “michael.nitschinger@...” } Meta InformaCon Including Key All Keys Unique and Kept in RAM Document Value Most Recent In Ram And Persisted To Disk Document Structure with JSON
use cases Simple secondary indexes (the most common) Complex secondary, terCary and composite indexes AggregaCon funcCons (reducCon) • Example: count the number of North American Ales Organizing related data • Built using Map/Reduce Map funcCon creates the index (b-‐tree) Reduce funcCon summarizes (reduces) informaCon Wrigen using superfast Javascript (V8)
Extends the Spymemcached Library • Asynchronous where possible • Dependencies: Negy, Apache HTTPCore (+NIO), Jetson • Either Download (hdp://www.couchbase.com/develop/java/current) • Or include through Maven (hdp://files.couchbase.com/maven2/) About the SDK (1)
(memcached, hgp) cluster configuraCon changes (add/remove) failover scenarios • Provides a unified API for key-‐ and view-‐based access APIs for bucket and design document management extended debugging and logging faciliCes About the SDK (2)
unified access pagerns on a variety of databases/frameworks without loosing flexibility and beger integraCon into the Spring ecosystem • Support for JPA Hadoop MongoDB Neo4J ....
• Use @Cacheable, @CacheEvict or @CachePut • Support for SpEL in those annotaCons • Translates to get/set/delete calls behind the scenes • Get distributed, high performance caching in a mager of minutes!
• RelaConships • SCll under heavy development • Work with your EnCCes (POJOs) in a tradiConal and natural way • Integrated ConfiguraCon for your Persistence.xml