0
Developing	  with	  Couchbase	  Part	  I:	                 Ge:ng	  Started	                     Raghavan	  “Rags”	  Sriniv...
Speaker	  IntroducQon	  •  Architect	  and	  Evangelist	  working	  with	  developers	  •  Speaker	  at	  JavaOne,	  RSA	 ...
Agenda	  •    Ge:ng	  Started	  •    An	  introducQon	  to	  Documents	  with	  Couchbase	  •    Couchbase	  server	  2.0	...
GETTING	  STARTED:	  DEVELOPMENT	  ENVIRONMENT	                                   4	  
Development	  Environment:	  Development	  DB	  •  Downloads	  at	  couchbase.com/download	    •  Linux:	  Ubuntu	  and	  ...
Development	  Environment:	  Obtaining	  a	  Client	  •  High	  performance,	  official	  client	  libraries	  for	  Java,	 ...
Client	  Setup:	  Ge:ng	  Cluster	  ConfiguraQon	        Couchbase	  Client	                              Cluster	  Configur...
Client	  at	  RunQme:	  Adding	  a	  node	              Couchbase	  Client	                                               ...
Client	  Set	  up	  at	  a	  Code	  Level	  // Set up at least two URIs in case one server fails!URI server = new URI(http...
OperaQons	  Available	  to	  a	  Client	  of	  Couchbase	  Server	  •  Store	  OperaQons	      –  Add:	  Store	  the	  doc...
A	  Distributed	  Hash	  Table	                                          ApplicaQon	                      set(key,	  value...
A	  Distributed	  Hash	  Table	  Document	  Store	                                                ApplicaQon	             ...
Distributed	  System	  Design:	  Concurrency	  Controls	                                                              Acto...
Common	  QuesQons	  with	  Metadata	         Document	  Metadata:	         •   TTL	         •   CAS	  value	         •   F...
INTRODUCING	  DOCUMENTS	                                 15	  
A	  JSON	  Document	                                   The primary key	{!     “id: beer_Hoptimus_Prime,!     “type”: “beer...
Other	  Documents	  and	  Document	  RelaQonships	  {    !     “id: beer_Hoptimus_Prime,!     “type” : “beer”,        !   ...
Simplicity	  of	  Document	  Oriented	  Datastore	  •  Schema	  is	  opQonal	      –  Technically,	  each	  document	  has...
Adding	  a	  Document:	  ObservaQons	  and	  ConsideraQons	  •  ObservaQons	      –  Conversion	  to	  document	  was	  ve...
Common	  QuesQons	  when	  AdopQng	  Couchbase	  Q:	  What	  if	  I	  need	  to	  fetch	  referenced	  documents?	  A:	  S...
COUCHBASE	  SERVER	  2.0	  	  COMPATIBLE	  LIBRARY	  FEATURES	                                          21	  
Couchbase	  Server	  2.0:	  Views	     •  Views	  can	  cover	  a	  few	  different	  use	  cases	         –  Simple	  seco...
Indexing	  and	  Querying	                     APP	  SERVER	  1	                                            APP	  SERVER	 ...
RESOURCES	  AND	  SUMMARY	                                    24	  
Resources,	  Summary	  and	  Call	  For	  AcQon	  •  Couchbase	  Server	  Downloads	      –  hnp://www.couchbase.com/downl...
THANKS	  -­‐	  QA	  Raghavan “Rags” Srinivas, Couchbase Inc.	  (rags@couchbase.com, @ragss)                               ...
Upcoming SlideShare
Loading in...5
×

CouchConf London Developing with Couchbase I: Getting Started

538

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
538
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "CouchConf London Developing with Couchbase I: Getting Started"

  1. 1. Developing  with  Couchbase  Part  I:   Ge:ng  Started   Raghavan  “Rags”  Srinivas   Developer  Advocate   rags@couchbase.com   1  
  2. 2. Speaker  IntroducQon  •  Architect  and  Evangelist  working  with  developers  •  Speaker  at  JavaOne,  RSA  conferences,  Sun  Tech  Days,   JUGs  and  other  developer  conferences  •  Taught  undergrad  and  grad  courses  •  Technology  Evangelist  at  Sun  Microsystems  for  10+   years  •  SQll  trying  to  understand  and  work  more  effecQvely  on   Java  and  distributed  systems  •  Couchbase  Developer  Advocate  working  with  Java  and   Ruby  developers  •  Philosophy:  “Be#er  to  have  an  unanswered  ques1on   than  a  unques1oned  answer”   2  
  3. 3. Agenda  •  Ge:ng  Started  •  An  introducQon  to  Documents  with  Couchbase  •  Couchbase  server  2.0  compaQble  client  libraries  •  Resources  and  Summary  •  Q/A   3  
  4. 4. GETTING  STARTED:  DEVELOPMENT  ENVIRONMENT   4  
  5. 5. Development  Environment:  Development  DB  •  Downloads  at  couchbase.com/download   •  Linux:  Ubuntu  and  Red  Hat/CentOS   –  Packages  for  most  common   distribuQons.   •  dpkg  -­‐i  ,  rpm  -­‐i,  etc.   •  Mac   –  Download  a  .zip,  open,  drag  to   ApplicaQons,   •  Windows   –  Download  a  setup.exe,  double  click   •  Provision  via  wizard  in  Web  Console   –  Or  provision  via  REST  interface:  operaQons  folks  to  automate  provisioning     (i.e  Chef,  puppet,  Rightscale  rightscript)   5  
  6. 6. 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  Ge:ng  Started   –  Ge:ng  started  guides   –  Tutorial  with  a  sample  applicaQon   –  A  complete  API  reference   *Current  version  0.6  as  of  2012-­‐03-­‐13   6  
  7. 7. Client  Setup:  Ge:ng  Cluster  ConfiguraQon   Couchbase  Client   Cluster  ConfiguraQon   over  REST   { … "bucketCapabilities": [h2p://myserver:8091/   "touch", "sync", "couchapi" ], "bucketCapabilitiesVer": "sync-1.0", "bucketType": ”couchbase", "name": "default", "nodeLocator": "vbucket", "nodes": [ ….   Couchbase   Couchbase   Couchbase   Couchbase   Server   Server   Server   Server   Node   Node   Node   Node   7  
  8. 8. Client  at  RunQme:  Adding  a  node   Couchbase  Client   New  node     Cluster coming  online   Topology Update Couchbase   Couchbase   Couchbase   Couchbase   Couchbase   Server   Server   Server   Server   Server   Node   Node   Node   Node   Node   8  
  9. 9. Client  Set  up  at  a  Code  Level  // Set up at least two URIs in case one server fails!URI server = new URI(http://10.1.6.171:8091/pools/);!ListURI servers = new ArrayListURI();
servers.add(server);!!!// Now create a client talking to the default bucket!CouchbaseClient cbc = 
 new CouchbaseClient(servers, default, );!!System.err.println(cbc.get(“Rags) + ! is off Minding the Gap!!);! Use  the  Java  client  with  your  favorite  JSON  library:  Je@son,  Google  GSON,  etc.   Use  other  client  libraries  such  as  yajl  for  Ruby   9  
  10. 10. OperaQons  Available  to  a  Client  of  Couchbase  Server  •  Store  OperaQons   –  Add:  Store  the  document  if  it  does  not  yet  exist   –  Set:  Store  the  document,  overwriQng  exisQng  if  necessary  •  Retrieve  OperaQons   –  Get:  Fetch  the  document   –  Get  and  touch:  Fetch  the  document  and  update  the  TTL   –  MulQget:  Fetch  mulQple  documents  at  the  same  Qme  •  Update  operaQons   –  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   10  
  11. 11. A  Distributed  Hash  Table   ApplicaQon   set(key,  value)   get(key)   returns  value   Database   DData   Cluster   11  
  12. 12. A  Distributed  Hash  Table  Document  Store   ApplicaQon   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   12  
  13. 13. Distributed  System  Design:  Concurrency  Controls   Actor  1   Actor  2   •  Compare  and  Swap  OperaQons   –  Olen  referred  to  as  “CAS”   –  OpQmisQc  concurrency  control   Success   CAS  mismatch   –  Available  with  many  mutaQon   operaQons,  depending  on  client.   •  Get  with  Lock   Couchbase  Server   –  Olen  referred  to  as  “GETL”   –  PessimisQc  concurrency  control   –  Locks  have  a  short  TTL   A   –  Locks  released  with  CAS   operaQons   –  Useful  when  working  with  object   B   C   D   graphs   F   E   13  
  14. 14. Common  QuesQons  with  Metadata   Document  Metadata:   •  TTL   •  CAS  value   •  Flags  Q:  What  happens  to  a  document  persisted  aKer  it’s  TTL?  A:  A  regular  background  job  will  remove  expired  documents.    Q:  How  do  I  use  flags?  A:  Frequently  used  to  idenQfy  data  type  or  other  anributes,  such  as  compression.    Behavior  varies  from  client  to  client.   14  
  15. 15. INTRODUCING  DOCUMENTS   15  
  16. 16. 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,!}! 16  
  17. 17. Other  Documents  and  Document  RelaQonships  { ! “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,
 Afterthought updated: 2010-07-22 20:00:20,
 latitude: -75.928469,
 longitude: 40.325725! }! 17  
  18. 18. Simplicity  of  Document  Oriented  Datastore  •  Schema  is  opQonal   –  Technically,  each  document  has  an  implicit  schema   –  Extend  the  schema  at  any  Qme!   •  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   18  
  19. 19. Adding  a  Document:  ObservaQons  and  ConsideraQons  •  ObservaQons   –  Conversion  to  document  was  very  simple,  many  JSON  opQons   –  Flexible  schema:  Did  not  need  to  add  the  laQtude  and  longitude    to   every  record   –  Flexible  schema:  Can  add  the  brewery  detail  later    •  ConsideraQons   –  Use  a  “type”  field  for  high  level  filtering  on  object  types   –  Why  use  a  parQcular  key/_id  :   ”beer_My_Brew”! –  Should  I  have  a  TTL?   19  
  20. 20. Common  QuesQons  when  AdopQng  Couchbase  Q:  What  if  I  need  to  fetch  referenced  documents?  A:  Simply  get  them  one  aler  another  or  use  another  View.        Q:  How  can  I  update  just  a  small  por1on  of  a  document?  A:  The  best  approach  is  to  keep  the  document  model  live  in  your  applicaQon,  then  use  CAS  operaQons  to  store  modified  documents.    The  Ruby  sample  applicaQon  has  a  good  example.    Q:  I  currently  use  serialized  objects  with  memcached  or  Membase,  can  I  do  this  s1ll  with  Couchbase  Server?  A:  Absolutely!    Everything  previously  supported  and  used  is  sQll  there.    JSON  offers  advantages  with  heterogenenous  plasorm  support  and  preparing  for  Couchbase  2.0  views.   20  
  21. 21. COUCHBASE  SERVER  2.0    COMPATIBLE  LIBRARY  FEATURES   21  
  22. 22. Couchbase  Server  2.0:  Views   •  Views  can  cover  a  few  different  use  cases   –  Simple  secondary  indexes  (the  most  common)   –  AggregaQon  funcQons   •  Example:  count  the  number  of  North  American  Ales   –  Organizing  related  data   22  
  23. 23. 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  MAP   AP   CLUSTER  M     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   AcQve  Docs     AcQve  Docs     AcQve  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         23  
  24. 24. RESOURCES  AND  SUMMARY   24  
  25. 25. Resources,  Summary  and  Call  For  AcQon  •  Couchbase  Server  Downloads   –  hnp://www.couchbase.com/downloads-­‐all   –  hnp://www.couchbase.com/couchbase-­‐server/overview  •  Developing  with  Client  libraries   –  hnp://www.couchbase.com/develop/java/current  (example)  •  Couchbase  forums   –  hnp://www.couchbase.com/forums/     25  
  26. 26. THANKS  -­‐  QA  Raghavan “Rags” Srinivas, Couchbase Inc.  (rags@couchbase.com, @ragss) 26  
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×