• Share
  • Email
  • Embed
  • Like
  • Private Content
Developing with couchbase i getting started v3
 

Developing with couchbase i getting started v3

on

  • 1,126 views

 

Statistics

Views

Total Views
1,126
Views on SlideShare
1,126
Embed Views
0

Actions

Likes
0
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • By design, installation of couchbase server is easy.
  • Again, quick. show it is all simple:gem install, easy_install, peclisntall, mvnisnstall, etc ...
  • Although NoSQL is heavily mentioned in the context of scalibility another very critical concept is simplifying the architecture. A truly distributed key value pair is the answer. From a developer/perspective the API does not change. It’s as good as using the Java Hash or Hash Set APIs except that the infrastructure hides the details.We will see that by using JSON/HTTP and REST which are ubiquitous in nature, it’s possible to develop applications for multiple clients using very simple apis.
  • Although NoSQL is heavily mentioned in the context of scalibility another very critical concept is simplifying the architecture. A truly distributed key value pair is the answer. From a developer/perspective the API does not change. It’s as good as using the Java Hash or Hash Set APIs except that the infrastructure hides the details.We will see that by using JSON/HTTP and REST which are ubiquitous in nature, it’s possible to develop applications for multiple clients using very simple apis.
  • TODO: replace couchbase server with a logo
  • 1. _ids2. ignore _rev3. data types
  • 1. _ids2. ignore _rev3. data types
  • TODO: find a real brewery documentThere is a different schema between this beer and it's brewery. Obviously, there is a relationship but while a beer has an address, it's pretty temporary. A brewery probably technically has an alcohol by volume, but it's not commonly measured or tracked.
  • [FIXME] Title

Developing with couchbase i getting started v3 Developing with couchbase i getting started v3 Presentation Transcript

  • Developing with Couchbase Part I: Getting Started John Zablocki Developer Advocate john@couchbase.com 1
  • About Me{ " _id" : "John Zablocki”, "Title" : "Developer Advocate", "Company" : "Couchbase", "Books" : [ { "Title" : "Orchard CMS", "Publisher" : "OReilly" } ], "Twitter" : "@CodeVoyeur", "Email" : "john@couchbase.com", "Meetup" : "Beantown ALT.NET“, "Code" : [ "https://github.com/jzablocki", http://bitbucket.com/johnzablockis ], "Blogs" : [ "http://dllhell.net", "http://blog.couchbase.com" ]} 2
  • Agenda• Setup• Operations• Introducing Documents• Common Questions• Resources and Summary• Q/A 3
  • SETUPSetup Operations Introducing Common Resources and Documents Questions Summary 4
  • Development Environment: Development DB• Downloads at couchbase.com/download • Linux: Ubuntu and Red Hat/CentOS – Packages for most common distributions. • dpkg -i , rpm -i, etc. • Mac – Download a .zip, open, drag to Applications, • Windows – Download a setup.exe, double click • Provision via wizard in Web Console – Or provision via REST interface: operations folks to automate provisioning (i.e Chef, puppet, Rightscale rightscript) 5
  • Development Environment: Obtaining a Client• High performance, official client libraries for Java, .NET, PHP, Ruby, C, Python*• Head to couchbase.com/develop for SDKs where you will find – Client libraries – Screencasts on Getting Started – Getting started guides – Tutorial with a sample application – A complete API reference 6
  • Client Setup: Getting Cluster Configuration Couchbase Client Cluster Configuration over REST {
… "bucketCapabilities": [
 "touch", 
 "sync", 
 "name": "default", 
 "nodeLocator": "vbucket", 
http://myserver:8091/ …. Couchbase Couchbase Couchbase Couchbase Server Node Server Node Server Node Server Node 7
  • Client at Runtime: Adding a node Couchbase Client New node Cluster coming online Topology UpdateCouchbase Couchbase Couchbase Couchbase Couchbase Server Server Server Server Server Node Node Node Node Node 8
  • OPERATIONSSetup Operations Introducing Common Resources and Documents Questions Summary 9
  • A Simple “Hello World” Program<?php$cb = new Couchbase("127.0.0.1:8091"); // uses the default bucket// or specify a specific bucket like so://$cb = new Couchbase(”host:8091", "bucket", "pass", "bucket");$cb->set("spoon", "Hello World");var_dump($cb->get("spoon"));?> 10
  • Writing JSON<?php$cb = new Couchbase("127.0.0.1:8091”);$cb->set("beer_Zelta", "{"brewery":"Aldaris","name":"Zelta","abv":"5","updated":"2010-07-22 20:00:20"}");var_dump($cb->get("beer_Zelta"));?> Use your platform’s favorite JSON library: Jettison, Google GSON, etc. Use other client libraries such as JSON.NETfor .NET 11
  • Operations Available to a Client of Couchbase Server• Store Operations – Add: Store the document if it does not yet exist – Set: Store the document, overwriting existing if necessary• Retrieve Operations – Get: Fetch the document – Get and touch: Fetch the document and update the TTL – Getl/unlock: Get Lock and Unlock (more later) – Multiget: Fetch multiple documents at the same time• Update operations – Append/prepend: Add data in front of or on the end of a document – Delete: Remove the document from the store – Compare and Swap (CAS): Replace the current document, if CAS matches – Replace: Replace the document if it exists, otherwise do not – Touch: Update the TTL for a document Note: Not all Client Libraries are created equal 12
  • Time To Live (TTL)• TTL – Property to set expiration on the document – the actual value sent may either be – Unix time (number of seconds since January 1, 1970, as a 32- bit value – OR number of seconds starting from current time. number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days) – if the number sent by a client is larger than – that, the server will consider it to be real Unix time value rather than an offset from current time. 13
  • A Distributed Hash Table Application set(key, value) get(key) returns value Database DData Cluster 14
  • A Distributed Hash Table Document Store Application set(key, json) get(key) returns json Database{ DData“id": ”brewery_Legacy”,“type” : “brewery”,"name" : "Legacy Brewing”,“address": "525 Canal Street Reading","updated": "2010-07-22 20:00:20",} Cluster 15
  • Distributed System Design: Concurrency Controls Actor 1 Actor 2 • Compare and Swap Operations – Often referred to as “CAS” – Optimistic concurrency control Success CAS mismatch – Available with many mutation operations, depending on client. • Get with Lock Couchbase Server – Often referred to as “GETL” – Pessimistic concurrency control – Locks have a short TTL A – Locks released with CAS operations – Useful when working with object B C D graphs F E 16
  • INTRODUCING DOCUMENTSSetup Operations Introducing Common Resources and Documents Questions Summary 17
  • Sample App -- Beernique 18
  • E-R Diagram for Beernique (1, N) User Drinks Name email (1, N) Beer Brew (1,M)Id Name ABV … Brewery … Id Name State 19
  • A JSON Document The primary key{ “id": "beer_Hoptimus_Prime", “type”: “beer”, "abv": 10.0, The type information "brewery": "Legacy Brewing Co.", A float "category": "North American Ale", "name": "Hoptimus Prime", "style": "Imperial or Double India Pale Ale",} 20
  • Other Documents and Document Relationships{ “id": "beer_Hoptimus_Prime", “type” : “beer”, "abv": 10.0, "brewery": ”brewery_Legacy_Brewing_Co", "category": "North American Ale", "name": "Hoptimus Prime", "style": “Double India Pale Ale”} { “id": ”brewery_Legacy_Brewing_Co”, “type” : “brewery”, "name" : "Legacy Brewing Co.", "address": "525 Canal Street Reading, Pennsylvania, 19601 United States", "updated": "2010-07-22 20:00:20", "latitude": -75.928469, Spatial "longitude": 40.325725 } 21
  • Simplicity of Document Oriented Datastore• Schema is optional – Technically, each document has an implicit schema – Extend the schema at any time! • Need a new field? Add it. Define a default for similar objects which may not have this field yet.• Data is self-contained – Documents more naturally support the world around you, the data structures around you• Model data for your App/Code instead for the Database 22
  • Adding a Document: Observations and Considerations• Observations – Conversion to document was very simple, many JSON options – Flexible schema: Did not need to add the latitude and longitude to every record – Flexible schema: Can add the brewery detail later• Considerations – Use a “type” field for high level filtering on object types – Why use a particular key/_id : ”beer_My_Brew” – Should I have a TTL? 23
  • COMMON QUESTIONSSetup Operations Introducing Common Resources and Documents Questions Summary 24
  • Common Questions when Adopting CouchbaseQ: What if I need to fetch referenced documents?A: Simply get them one after another or use another View.Q: How can I update just a small portion of a document?A: The best approach is to keep the document model live in your application, thenuse CAS operations to store modified documents.Q: I currently use serialized objects with memcached or Membase, can I do this stillwith Couchbase Server?A: Absolutely! Everything previously supported and used is still there. JSON offersadvantages with heterogeneous platform support and preparing for Couchbase2.0 views.Q: How do I use flags?A: Frequently used to identify data type or other attributes, such as compression.Behavior varies from client to client. 25
  • Couchbase Server 2.0: Views • Views can cover a few different use cases – Simple secondary indexes (the most common) – Aggregation functions • Example: count the number of North American Ales – Organizing related data 26
  • Indexing and Querying APP SERVER 1 APP SERVER 2 APP SERVER 1 APP SERVER 2 COUCHBASE CLIENT LIBRARY COUCHBASE CLIENT LIBRARY COUCHBASE CLIENT LIBRARY COUCHBASE CLIENT LIBRARY  Indexing work is distributed CLUSTER MAP MAP CLUSTER CLUSTER MAPMAP CLUSTER amongst nodes  Large data set possible  Parallelize the effort  Each node has index for data Query Response stored on it  Queries combine the results from required nodes SERVER 1 SERVER 2 SERVER 3 Active Docs Active Docs Active Docs Doc 5 DOC Doc 4 DOC Doc 1 DOC Doc 2 DOC Doc 7 DOC Doc 3 DOC Doc 9 DOC Doc 8 DOC Doc 6 DOC Replica Docs Replica Docs Replica Docs Doc 4 DOC Doc 6 DOC Doc 7 DOC Doc 1 DOC Doc 3 DOC Doc 9 DOC Doc 8 DOC Doc 2 DOC Doc 5 DOC 27
  • RESOURCES AND SUMMARYSetup Operations Introducing Common Resources and Documents Questions Summary 28
  • Resources, Summary and Call For Action• Couchbase Server Downloads – http://www.couchbase.com/downloads-all – http://www.couchbase.com/couchbase-server/overview• Developing with Client libraries – http://www.couchbase.com/develop/• Couchbase forums – http://www.couchbase.com/forums/ 29
  • THANKS - Q&AJohn Zablocki, Couchbase Inc.(john@couchbase.com, @codevoyeur) 30