SlideShare a Scribd company logo
1 of 26
Developing	
  With	
  Documents:	
  
 Schemas	
  and	
  Rela8onships	
  




                                       1	
  1	
  
What	
  we ll	
  talk	
  about	
  


• Working	
  with	
  JSON	
  documents	
  
• Run8me-­‐driven	
  paCerns	
  for	
  
  • linking	
  between	
  documents	
  
  • embedding	
  data	
  
  • fetching	
  mul8ple	
  documents	
  




                                             2	
  
JSON	
  Documents	
  




                        3	
  3	
  
Couchbase	
  Server	
  is	
  a	
  Document	
  Database	
  




               hCp://mar8nfowler.com/bliki/AggregateOrientedDatabase.html	
  

      This synergy between the programming model and the distribution model is very valuable.	

      It allows the database to use its knowledge of how the application programmer clusters the data
      to help performance across the cluster.	

                                                                                                        4	
  
Document	
  Database	
  

                               o::1001	
  
                               {	
  
                               uid:	
  ji22jd,	
  
                               customer:	
  Ann,	
  
                               line_items:	
  [	
  	
  
                                         {	
  sku:	
  0321293533,	
  quan:	
  3,	
  	
  unit_price:	
  48.0	
  },	
  
                                         {	
  sku:	
  0321601912,	
  quan:	
  1,	
  unit_price:	
  39.0	
  },	
  
                                         {	
  sku:	
  0131495054,	
  quan:	
  1,	
  unit_price:	
  51.0	
  }	
  	
  
                               ],	
  
                               payment:	
  {	
  type:	
  Amex,	
  expiry:	
  04/2001,	
  	
  
                                         last5:	
  12345	
  }	
  
                               }	
  
                                         	
  




    •  Easy	
  to	
  distribute	
  data	
  
    •  Makes	
  sense	
  to	
  applica8on	
  programmers	
  
    	
                                                                                                                  5	
  
JSON	
  Documents	
  

•  Map	
  more	
  closely	
  to	
  objects	
  or	
  en88es	
  
•  CRUD	
  Opera8ons,	
  lightweight	
  schema	
  
         myDocument = {!
            fields : [ with basic types , 3.14159, true],!
            like : your favorite language. ,!
            status : {!
              apis : true,!
              databases : document }!
         }!
•  Stored	
  under	
  a	
  unique	
  iden8fier	
  key	
  

     client.set( mydocumentid , myDocument);!
     mySavedDocument = client.get( mydocumentid );!
                                                                 6	
  
Object	
  to	
  JSON	
  back	
  to	
  Object	
  

User	
  Object	
                 u::jasdeep@couchbase.com	
  
                                 {	
                                                  set()	
  
 string	
   uid	
  
                                     uid :	
  123456,	
  
 string	
   firstname	
               firstname :	
   jasdeep ,	
  
 string	
   lastname	
               lastname :	
   Jaitla ,	
  
 int	
       age	
                   age :	
  22,	
  
                                     favorite_colors :	
  [ blue ,	
   black ],	
  
 array	
   favorite_colors	
         email :	
   jasdeep@couchbase.com 	
  
 string	
   email	
              }	
  


User	
  Object	
                 u::jasdeep@couchbase.com	
  
                                 {	
                                                  get()	
  
 string	
   uid	
  
                                     uid :	
  123456,	
  
 string	
   firstname	
               firstname :	
   jasdeep ,	
  
 string	
   lastname	
               lastname :	
   Jaitla ,	
  
 int	
       age	
                   age :	
  22,	
  
                                     favorite_colors :	
  [ blue ,	
   black ],	
  
 array	
   favorite_colors	
         email :	
   jasdeep@couchbase.com 	
  
 string	
   email	
              }	
  
                                                                                                  7	
  
Meta	
  +	
  Document	
  Body	
  
	
  
{	
                                                                      Document	

	
  	
  	
  "brewery":	
  "New	
  Belgium	
  Brewing",	
                  user data,	

	
  	
  	
  "name":	
  "1554	
  Enlightened	
  Black	
  Ale",	
        can be anything	

	
  	
  	
  "abv":	
  5.5,	
  
	
  	
  	
  "descrip8on":	
  "Born	
  of	
  a	
  flood...",	
  
	
  	
  	
  "category":	
  "Belgian	
  and	
  French	
  Ale",	
  
	
  	
  	
  "style":	
  "Other	
  Belgian-­‐Style	
  Ales",	
  
	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20"	
  
}	
  
	
                          unique ID	

     vintage date format from an SQL dump
{	
                                                               >_<	

	
  	
  	
  "id"	
  :	
  "beer_Enlightened_Black_Ale ,	
                   Metadata	

	
  	
  	
  	
  	
  ...	
                                                   identifier,	

{	
                                                                       expiration, etc	

                                                                                               8	
  
No	
  More	
  ALTER	
  table	
  


• No	
  More	
  alter	
  table	
  
• More	
  produc8ve	
  developers!	
  
• Emergent	
  schema	
  
• Schema	
  driven	
  by	
  code	
  




                                         9	
  
Live	
  Data	
  




                    10	
  
                   10	
  
Real8me	
  Interac8ve	
  CRUD	
  




  •  Requirement:	
  high-­‐performance	
  with	
  high-­‐
     concurrency	
  and	
  dynamic	
  scale	
  
  •  Key/value	
  API	
  is	
  the	
  interac8ve	
  low-­‐latency	
  path	
  
                                                                                11	
  
Couchbase	
  Basic	
  Opera8ons	
  

 •  get	
  (key)	
  
    – 	
  Retrieve	
  a	
  document	
  
 •  set	
  (key,	
  value)	
  
    – 	
  Store	
  a	
  document,	
  overwrites	
  if	
  exists	
  
 •  add	
  (key,	
  value)	
  
    – 	
  Store	
  a	
  document,	
  error/excep8on	
  if	
  exists	
  
 •  replace	
  (key,	
  value)	
  
    – 	
  Store	
  a	
  document,	
  error/excep8on	
  if	
  doesn t	
  exist	
  
 •  cas	
  (key,	
  value,	
  cas)	
  
    – 	
  Compare	
  and	
  swap,	
  mutate	
  document	
  only	
  if	
  it	
  hasn t	
  changed	
  
      while	
  execu8ng	
  this	
  opera8on	
  
                                                                                                  12	
  
Couchbase	
  Basic	
  Opera8ons	
  (cont d)	
  

 Atomic	
  Counters	
  are	
  a	
  special	
  structure	
  in	
  Couchbase,	
  they	
  
 are	
  executed	
  in	
  order	
  and	
  are	
  Posi8ve	
  Integer	
  Values	
  
 • set	
  (key,	
  value)	
  
    – 	
  Use	
  set	
  to	
  ini8alize	
  the	
  counter	
  
        •  cb.set( my_counter ,	
  1)	
  
 • incr	
  (key)	
  
    – 	
  Increase	
  an	
  atomic	
  counter	
  value,	
  default	
  by	
  1	
  
        •  cb.incr( my_counter )	
  #	
  now	
  it s	
  2	
  
 • decr	
  (key)	
  
    – 	
  Decrease	
  an	
  atomic	
  counter	
  value,	
  default	
  by	
  1	
  
        •  cb.decr( my_counter )	
  #	
  now	
  it s	
  1	
  


                                                                                          13	
  
Simple	
  Example	
  in	
  Ruby	
  

 #	
  example.rb	
                                        #	
  user.rb	
  
                                                          require	
   rubygems 	
  
 require	
   ./user.rb 	
  
                                                          require	
   couchbase 	
  
 	
                                                       	
  
 u1	
  =	
  User.new({	
  	
                              class	
  User	
  
            :email	
  =>	
   jasdeep@scalabl3.com ,	
     aCr_accessor	
  	
  :name,	
  :email,	
  :8tle,	
  :twiCer	
  
            :name	
  =>	
   Jasdeep	
  Jaitla ,	
         	
  
                                                          def	
  ini8alize(aCr	
  =	
  {})	
  	
  	
  	
  	
  	
  	
  aCr.each	
  do	
  |name,	
  value|	
  	
  	
  	
  	
  	
  	
  
            :8tle	
  =>	
   Scalability	
  Sherpa ,	
  
                                                          seCer	
  =	
  "#{name}="	
  	
  	
  	
  	
  	
  	
  next	
  unless	
  respond_to?(seCer)	
  	
  	
  	
  	
  	
  	
  
            :twiCer	
  =>	
   @scalabl3	
                 send(seCer,	
  value)	
  	
  	
  	
  	
  	
  	
  end	
  
 })	
                                                     end	
  
 	
                                                       	
  
 u1.save	
                                                def	
  save	
  
                                                                           C	
  =	
  Couchbase.bucket	
  
                                                                           C.	
  set(@email.downcase,	
  self.to_json)	
  
                                                          end	
  
                                                          end	
  




                                                                                                                                                                           14	
  
Run8me	
  Driven	
  Schema	
  


 •  What s	
  in	
  the	
  database	
  looks	
  more	
  like	
  your	
  code	
  
 •  Thinking	
  about	
  throughput,	
  latency,	
  update	
  and	
  read	
  paCerns	
  is	
  the	
  
    new	
  data	
  modeling	
  
 •  Data	
  flows	
  get	
  more	
  aCen8on	
  than	
  data	
  at	
  rest	
  

 •  When	
  should	
  I	
  split	
  a	
  data-­‐structure	
  into	
  mul8ple	
  documents?	
  
    •  Generally	
  the	
  more	
  useful	
  your	
  document	
  is	
  as	
  a	
  standalone	
  en8ty,	
  
       the	
  beCer.	
  
    •  Documents	
  that	
  grow	
  without	
  bound	
  are	
  bad	
  




                                                                                                             15	
  
Link	
  Between	
  Documents	
  




                                    16	
  
                                   16	
  
Let s	
  Add	
  Comments	
  and	
  Ra8ngs	
  to	
  the	
  Beer	
  

  •  Challenge	
  linking	
  documents	
  together	
  
  •  Whether	
  to	
  grow	
  an	
  exis8ng	
  document	
  or	
  store	
  
     independent	
  documents	
  
  •  No	
  transac8onality	
  between	
  documents!	
  
      	
         good w/ burgers	

      {	
  
      	
  	
  	
  "brewery":	
  "New	
  Belgium	
  Brewing",	
  
                                                                          I give that a 5!	

      	
  	
  	
  "name":	
  "1554	
  Enlightened	
  Black	
  Ale",	
  
      	
  	
  	
  "abv":	
  5.5,	
  
      	
  	
  	
  "descrip8on":	
  "Born	
  of	
  a	
  flood...",	
          tastes like
      	
  	
  	
  "category":	
  "Belgian	
  and	
  French	
  Ale",	
        college!	

      	
  	
  	
  "style":	
  "Other	
  Belgian-­‐Style	
  Ales",	
  
      	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20"	
  
      }	
                                                                                   17	
  
      	
  
Let s	
  Add	
  Comments	
  and	
  Ra8ngs	
  to	
  the	
  Beer	
  

       •  Put	
  comments	
  in	
  their	
  own	
  documents	
  
       •  And	
  add	
  the	
  ra8ngs	
  to	
  the	
  beer	
  document	
  itself.	
  
	
  
{	
                                                            	
  
                                                               {	
  
	
  	
  	
  "type":	
  "comment",	
                            	
  	
  	
  "brewery":	
  "New	
  Belgium	
  Brewing",	
  
	
  	
  	
  "about_id":	
  "beer_Enlightened_Black_Ale",	
     	
  	
  	
  "name":	
  "1554	
  Enlightened	
  Black	
  Ale",	
  
	
  	
  	
  "user_id":	
  525,	
                               	
  	
  	
  "abv":	
  5.5,	
  
	
  	
  	
  "text":	
  "tastes	
  like	
  college!",	
         	
  	
  	
  "descrip8on":	
  "Born	
  of	
  a	
  flood...",	
  
	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20"	
       	
  	
  	
  "category":	
  "Belgian	
  and	
  French	
  Ale",	
  
}	
                                                                                                   	

                                                               	
  	
  	
  "style":	
  "Other	
  Belgian-­‐Style	
  Ales",	
  
                                                               	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20",	
  
                                                               	
  	
   ra8ngs 	
  :	
  {	
  


                          I give that a 5!	

                                                               	
  	
  	
  	
   525 	
  :	
  5,	
  
                                                               	
  	
  	
  	
   30 	
  :	
  4,	
      	

                                                               	
  	
  	
  	
   1044 	
  :	
  2	
  
                                                               	
  },	
  
                                                               	
  	
   comments 	
  :	
  [	
  
                                                               	
  	
  	
  	
  	
   f1e62 ,	
  
                                                               	
  	
  	
  	
  	
   6ad8c 	
  
                                                               	
  	
  	
  ]	
  
                                                               }	
                                                                 18	
  
                                                               	
  
 
{	
                                                            	
  
	
  	
  	
  "type":	
  "user",	
                               {	
  
	
  	
  	
  "user_id":	
  525,	
                               	
  	
  	
  "brewery":	
  "New	
  Belgium	
  Brewing",	
  
	
  	
  	
  "name":	
  "Chris",	
                              	
  	
  	
  "name":	
  "1554	
  Enlightened	
  Black	
  Ale",	
  
	
  	
  	
  "email":	
  "jchris@couchbase.com"	
               	
  	
  	
  "abv":	
  5.5,	
  
}	
                                                            	
  	
  	
  "descrip8on":	
  "Born	
  of	
  a	
  flood...",	
  
                                                               	
  	
  	
  "category":	
  "Belgian	
  and	
  French	
  Ale",	
  
                                                               	
  	
  	
  "style":	
  "Other	
  Belgian-­‐Style	
  Ales",	
  
                                                               	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20",	
  
                                                               	
  	
   ra8ngs 	
  :	
  {	
  
                                       I give tha
                                                 t a 5!	

                                  	

                                                               	
  	
  	
  	
   525 	
  :	
  5,	
  
                                                               	
  	
  	
  	
   30 	
  :	
  4,	
  
	
  
{	
                                                            	
  },	
                     	

                                                               	
  	
  	
  	
   1044 	
  :	
  2	
  

	
  	
  	
  "type":	
  "comment",	
                            	
  	
   comments 	
  :	
  [	
  
	
  	
  	
  "about_id":	
  "beer_Enlightened_Black_Ale",	
     	
  	
  	
  	
  	
   f1e62 ,	
  
	
  	
  	
  "user_id":	
  525,	
                               	
  	
  	
  	
  	
   6ad8c 	
  
	
  	
  	
  "text":	
  "tastes	
  like	
  college!",	
         	
  	
  	
  ]	
  
	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20"	
       }	
  
}	
                                                            	
  
Do	
  it:	
  save	
  the	
  comment	
  document	
  

  •  Set	
  at	
  the	
  id	
   f1e62 	
  

    client.set( f1e62 ,{!
     	
  
    !
        	
  
    !                                                                              create a new
        	
  	
  	
  "type":	
  "comment",	
  
    !
    !   	
  	
  	
  "about_id”:"beer_Enlightened_Black_Ale",	
   document	

    !   	
  	
  	
  "user_id":	
  525,	
  
    !   	
  	
  	
  "text":	
  "tastes	
  like	
  college!",	
     	
  
    !   	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20"	
   {	
  
    !   	
                                                         	
  	
  	
  "id":	
  "f1e62"	
  
    !                                                              }	
  
    });!


                                                                                                      20	
  
Link	
  between	
  comments	
  and	
  beers	
  
              	
  
          {	
  
                                                                         	
  
          	
  	
  	
  "type":	
  "comment",	
                            {	
  
          	
  	
  	
  "about_id":	
  "beer_Enlightened_Black_Ale",	
     	
  	
  	
  "brewery":	
  "New	
  Belgium	
  Brewing",	
  
link to 	
  	
  	
  "user_id":	
  525,	
  
                                                                         	
  	
  	
  "name":	
  "1554	
  Enlightened	
  Black	
  Ale",	
  
  beer	

 	
  	
  	
  "text":	
  "tastes	
  like	
  college!",	
         	
  	
  	
  "abv":	
  5.5,	
  
          	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20"	
       	
  	
  	
  "descrip8on":	
  "Born	
  of	
  a	
  flood...",	
  
          }	
                                                            	
  	
  	
  "category":	
  "Belgian	
  and	
  French	
  Ale",	
  
                                                                         	
  	
  	
  "style":	
  "Other	
  Belgian-­‐Style	
  Ales",	
  

        	
                                                                                           	

                                                                         	
  	
  	
  "updated":	
  "2010-­‐07-­‐22	
  20:00:20",	
  
                                                                         	
  	
   ra8ngs 	
  :	
  {	
  
                                                                         	
  	
  	
  	
   525 	
  :	
  5,	
  
        {	
  
        	
  	
  	
  "id":	
  "f1e62"	
  
                                                                                                     	

                                                                         	
  	
  	
  	
   30 	
  :	
  4,	
  
                                                                         	
  	
  	
  	
   1044 	
  :	
  2	
  
                                                                         	
  },	
  
        }	
                                                              	
  	
   comment_ids 	
  :	
  [	
  
                                                                         	
  	
  	
  	
  	
   f1e62 ,	
  
                                                  link to                	
  	
  	
  	
  	
   6ad8c 	
  
                                                                         	
  	
  	
  ]	
  
                                                comments	

              }	
  
                                                                         	
  


                                                                                                                                      21	
  
How	
  to:	
  look	
  up	
  comments	
  from	
  a	
  beer	
  

        •  SERIALIZED	
  LOOP	
  	
  
           beer = client.get( beer:A_cold_one );!
           beer.comment_ids.each { |id|!
              comments.push(client.get(id));!
           }!

        •  FAST	
  MULTI-­‐KEY	
  LOOKUP	
  
    beer = client.get( beer:A_cold_one );!
    comments = client.multiGet(beer.comment_ids)!
    !
        •  ASYNC	
  VIEW	
  QUERY	
  
           comments = client.query( myapp , by_comment_on ,!
             {:key => beer:A_cold_one });!
           !
                                          figure	
  hCp://www.ibm.com/developerworks/webservices/library/ws-­‐sdoarch/	
  
                                                                                                                            22	
  
How	
  to:	
  add	
  a	
  ra8ng	
  to	
  a	
  beer	
  

 •  Other	
  users	
  are	
  ra8ngs	
  beers	
  also,	
  so	
  we	
  use	
  a	
  CAS	
  update	
  
      –  we	
  don t	
  want	
  to	
  accidentally	
  overwrite	
  another	
  users	
  ra8ng	
  that	
  is	
  being	
  saved	
  at	
  the	
  
         same	
  8me	
  as	
  ours	
  
 •  Best	
  prac8ce	
  is	
  to	
  use	
  a	
  lambda	
  so	
  the	
  client	
  can	
  retry	
  


         cb.cas("mykey") do |doc|      !
              doc["ratings"][current_user.id] = my_rating
              doc!
         end!
         !
                                                          Actor	
  1	
                  Actor	
  2	
  

                                                          Success	
                                CAS	
  mismatch	
  
                                                                                                   &	
  retry	
  

                                                                    Couchbase	
  Server	
  
                                                                                                                                                23	
  
Object	
  Graph	
  With	
  Shared	
  Interac8ve	
  Updates	
  

  •  Challenge:	
  higher	
  level	
  data	
  structures	
  
  •  Objects	
  shared	
  across	
  mul8ple	
  users	
  
  •  Mixed	
  object	
  sets	
  (upda8ng	
  some	
  private	
  and	
  some	
  
     shared	
  objects)	
  




                                            figure	
  hCp://www.ibm.com/developerworks/webservices/library/ws-­‐sdoarch/	
  
                                                                                                                              24	
  
Get	
  With	
  Lock	
  (GETL)	
  

 •    O{en	
  referred	
  to	
  as	
   GETL 	
  
 •    Pessimis8c	
  concurrency	
  control	
  
 •    Locks	
  have	
  a	
  short	
  TTL	
  
 •    Locks	
  released	
  with	
  CAS	
  opera8ons	
  
 •    Useful	
  when	
  working	
  with	
  object	
  graphs	
  




                                                                  25	
  
Ques8ons?	
  




                26	
   2

More Related Content

What's hot

Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Ralph Schindler
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBUwe Printz
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011Steven Francia
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
Webinar: Data Modeling Examples in the Real World
Webinar: Data Modeling Examples in the Real WorldWebinar: Data Modeling Examples in the Real World
Webinar: Data Modeling Examples in the Real WorldMongoDB
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperJonathan Wage
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data opsmnacos
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopPublicis Sapient Engineering
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMJonathan Wage
 
Rails Model Basics
Rails Model BasicsRails Model Basics
Rails Model BasicsJames Gray
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMJonathan Wage
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011Stephen Chin
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 

What's hot (20)

Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
Webinar: Data Modeling Examples in the Real World
Webinar: Data Modeling Examples in the Real WorldWebinar: Data Modeling Examples in the Real World
Webinar: Data Modeling Examples in the Real World
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document Mapper
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data ops
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
 
Rails Model Basics
Rails Model BasicsRails Model Basics
Rails Model Basics
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 

Viewers also liked

Couchbase Korea User Gorup 2nd Meetup #1
Couchbase Korea User Gorup 2nd Meetup #1Couchbase Korea User Gorup 2nd Meetup #1
Couchbase Korea User Gorup 2nd Meetup #1won min jang
 
Great Southern Music
Great Southern MusicGreat Southern Music
Great Southern Musicmystermagic
 
Gns sales force new features
Gns sales force   new featuresGns sales force   new features
Gns sales force new featuresgnsonline
 
기획1팀
기획1팀기획1팀
기획1팀Juno Lee
 
Fasilitas dan perlengkapan bulu tangkis
Fasilitas dan perlengkapan bulu tangkisFasilitas dan perlengkapan bulu tangkis
Fasilitas dan perlengkapan bulu tangkisAR NO
 

Viewers also liked (8)

Couchbase Korea User Gorup 2nd Meetup #1
Couchbase Korea User Gorup 2nd Meetup #1Couchbase Korea User Gorup 2nd Meetup #1
Couchbase Korea User Gorup 2nd Meetup #1
 
Clase n°2
Clase n°2Clase n°2
Clase n°2
 
Great Southern Music
Great Southern MusicGreat Southern Music
Great Southern Music
 
Gns sales force new features
Gns sales force   new featuresGns sales force   new features
Gns sales force new features
 
Test powerpoint
Test powerpointTest powerpoint
Test powerpoint
 
기획1팀
기획1팀기획1팀
기획1팀
 
Fasilitas dan perlengkapan bulu tangkis
Fasilitas dan perlengkapan bulu tangkisFasilitas dan perlengkapan bulu tangkis
Fasilitas dan perlengkapan bulu tangkis
 
Full user tour
Full user tourFull user tour
Full user tour
 

Similar to Couchbase Korea User Group 2nd Meetup #2

Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David SzakallasDatabricks
 
Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0Anuj Sahni
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redisDvir Volk
 
CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009Jason Davies
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DBMihail Mateev
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college projectAmitSharma397241
 
Getting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of DatastaxGetting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of DatastaxData Con LA
 
Scalding big ADta
Scalding big ADtaScalding big ADta
Scalding big ADtab0ris_1
 
How to use the new Domino Query Language
How to use the new Domino Query LanguageHow to use the new Domino Query Language
How to use the new Domino Query LanguageTim Davis
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 

Similar to Couchbase Korea User Group 2nd Meetup #2 (20)

Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David Szakallas
 
Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
 
CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Latinoware
LatinowareLatinoware
Latinoware
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
 
Getting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of DatastaxGetting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of Datastax
 
Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
 
Scalding big ADta
Scalding big ADtaScalding big ADta
Scalding big ADta
 
How to use the new Domino Query Language
How to use the new Domino Query LanguageHow to use the new Domino Query Language
How to use the new Domino Query Language
 
C# for beginners
C# for beginnersC# for beginners
C# for beginners
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Couch db
Couch dbCouch db
Couch db
 
MongoDB 3.0
MongoDB 3.0 MongoDB 3.0
MongoDB 3.0
 

Recently uploaded

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Couchbase Korea User Group 2nd Meetup #2

  • 1. Developing  With  Documents:   Schemas  and  Rela8onships   1  1  
  • 2. What  we ll  talk  about   • Working  with  JSON  documents   • Run8me-­‐driven  paCerns  for   • linking  between  documents   • embedding  data   • fetching  mul8ple  documents   2  
  • 4. Couchbase  Server  is  a  Document  Database   hCp://mar8nfowler.com/bliki/AggregateOrientedDatabase.html   This synergy between the programming model and the distribution model is very valuable. It allows the database to use its knowledge of how the application programmer clusters the data to help performance across the cluster. 4  
  • 5. Document  Database   o::1001   {   uid:  ji22jd,   customer:  Ann,   line_items:  [     {  sku:  0321293533,  quan:  3,    unit_price:  48.0  },   {  sku:  0321601912,  quan:  1,  unit_price:  39.0  },   {  sku:  0131495054,  quan:  1,  unit_price:  51.0  }     ],   payment:  {  type:  Amex,  expiry:  04/2001,     last5:  12345  }   }     •  Easy  to  distribute  data   •  Makes  sense  to  applica8on  programmers     5  
  • 6. JSON  Documents   •  Map  more  closely  to  objects  or  en88es   •  CRUD  Opera8ons,  lightweight  schema   myDocument = {! fields : [ with basic types , 3.14159, true],! like : your favorite language. ,! status : {! apis : true,! databases : document }! }! •  Stored  under  a  unique  iden8fier  key   client.set( mydocumentid , myDocument);! mySavedDocument = client.get( mydocumentid );! 6  
  • 7. Object  to  JSON  back  to  Object   User  Object   u::jasdeep@couchbase.com   {   set()   string   uid   uid :  123456,   string   firstname   firstname :   jasdeep ,   string   lastname   lastname :   Jaitla ,   int   age   age :  22,   favorite_colors :  [ blue ,   black ],   array   favorite_colors   email :   jasdeep@couchbase.com   string   email   }   User  Object   u::jasdeep@couchbase.com   {   get()   string   uid   uid :  123456,   string   firstname   firstname :   jasdeep ,   string   lastname   lastname :   Jaitla ,   int   age   age :  22,   favorite_colors :  [ blue ,   black ],   array   favorite_colors   email :   jasdeep@couchbase.com   string   email   }   7  
  • 8. Meta  +  Document  Body     {   Document      "brewery":  "New  Belgium  Brewing",   user data,      "name":  "1554  Enlightened  Black  Ale",   can be anything      "abv":  5.5,        "descrip8on":  "Born  of  a  flood...",        "category":  "Belgian  and  French  Ale",        "style":  "Other  Belgian-­‐Style  Ales",        "updated":  "2010-­‐07-­‐22  20:00:20"   }     unique ID vintage date format from an SQL dump {   >_<      "id"  :  "beer_Enlightened_Black_Ale ,   Metadata          ...   identifier, {   expiration, etc 8  
  • 9. No  More  ALTER  table   • No  More  alter  table   • More  produc8ve  developers!   • Emergent  schema   • Schema  driven  by  code   9  
  • 10. Live  Data   10   10  
  • 11. Real8me  Interac8ve  CRUD   •  Requirement:  high-­‐performance  with  high-­‐ concurrency  and  dynamic  scale   •  Key/value  API  is  the  interac8ve  low-­‐latency  path   11  
  • 12. Couchbase  Basic  Opera8ons   •  get  (key)   –   Retrieve  a  document   •  set  (key,  value)   –   Store  a  document,  overwrites  if  exists   •  add  (key,  value)   –   Store  a  document,  error/excep8on  if  exists   •  replace  (key,  value)   –   Store  a  document,  error/excep8on  if  doesn t  exist   •  cas  (key,  value,  cas)   –   Compare  and  swap,  mutate  document  only  if  it  hasn t  changed   while  execu8ng  this  opera8on   12  
  • 13. Couchbase  Basic  Opera8ons  (cont d)   Atomic  Counters  are  a  special  structure  in  Couchbase,  they   are  executed  in  order  and  are  Posi8ve  Integer  Values   • set  (key,  value)   –   Use  set  to  ini8alize  the  counter   •  cb.set( my_counter ,  1)   • incr  (key)   –   Increase  an  atomic  counter  value,  default  by  1   •  cb.incr( my_counter )  #  now  it s  2   • decr  (key)   –   Decrease  an  atomic  counter  value,  default  by  1   •  cb.decr( my_counter )  #  now  it s  1   13  
  • 14. Simple  Example  in  Ruby   #  example.rb   #  user.rb   require   rubygems   require   ./user.rb   require   couchbase       u1  =  User.new({     class  User   :email  =>   jasdeep@scalabl3.com ,   aCr_accessor    :name,  :email,  :8tle,  :twiCer   :name  =>   Jasdeep  Jaitla ,     def  ini8alize(aCr  =  {})              aCr.each  do  |name,  value|               :8tle  =>   Scalability  Sherpa ,   seCer  =  "#{name}="              next  unless  respond_to?(seCer)               :twiCer  =>   @scalabl3   send(seCer,  value)              end   })   end       u1.save   def  save   C  =  Couchbase.bucket   C.  set(@email.downcase,  self.to_json)   end   end   14  
  • 15. Run8me  Driven  Schema   •  What s  in  the  database  looks  more  like  your  code   •  Thinking  about  throughput,  latency,  update  and  read  paCerns  is  the   new  data  modeling   •  Data  flows  get  more  aCen8on  than  data  at  rest   •  When  should  I  split  a  data-­‐structure  into  mul8ple  documents?   •  Generally  the  more  useful  your  document  is  as  a  standalone  en8ty,   the  beCer.   •  Documents  that  grow  without  bound  are  bad   15  
  • 16. Link  Between  Documents   16   16  
  • 17. Let s  Add  Comments  and  Ra8ngs  to  the  Beer   •  Challenge  linking  documents  together   •  Whether  to  grow  an  exis8ng  document  or  store   independent  documents   •  No  transac8onality  between  documents!     good w/ burgers {        "brewery":  "New  Belgium  Brewing",   I give that a 5!      "name":  "1554  Enlightened  Black  Ale",        "abv":  5.5,        "descrip8on":  "Born  of  a  flood...",   tastes like      "category":  "Belgian  and  French  Ale",   college!      "style":  "Other  Belgian-­‐Style  Ales",        "updated":  "2010-­‐07-­‐22  20:00:20"   }   17    
  • 18. Let s  Add  Comments  and  Ra8ngs  to  the  Beer   •  Put  comments  in  their  own  documents   •  And  add  the  ra8ngs  to  the  beer  document  itself.     {     {        "type":  "comment",        "brewery":  "New  Belgium  Brewing",        "about_id":  "beer_Enlightened_Black_Ale",        "name":  "1554  Enlightened  Black  Ale",        "user_id":  525,        "abv":  5.5,        "text":  "tastes  like  college!",        "descrip8on":  "Born  of  a  flood...",        "updated":  "2010-­‐07-­‐22  20:00:20"        "category":  "Belgian  and  French  Ale",   }        "style":  "Other  Belgian-­‐Style  Ales",        "updated":  "2010-­‐07-­‐22  20:00:20",       ra8ngs  :  {   I give that a 5!         525  :  5,           30  :  4,           1044  :  2    },       comments  :  [             f1e62 ,             6ad8c        ]   }   18    
  • 19.   {          "type":  "user",   {        "user_id":  525,        "brewery":  "New  Belgium  Brewing",        "name":  "Chris",        "name":  "1554  Enlightened  Black  Ale",        "email":  "jchris@couchbase.com"        "abv":  5.5,   }        "descrip8on":  "Born  of  a  flood...",        "category":  "Belgian  and  French  Ale",        "style":  "Other  Belgian-­‐Style  Ales",        "updated":  "2010-­‐07-­‐22  20:00:20",       ra8ngs  :  {   I give tha t a 5!         525  :  5,           30  :  4,     {    },           1044  :  2        "type":  "comment",       comments  :  [        "about_id":  "beer_Enlightened_Black_Ale",             f1e62 ,        "user_id":  525,             6ad8c        "text":  "tastes  like  college!",        ]        "updated":  "2010-­‐07-­‐22  20:00:20"   }   }    
  • 20. Do  it:  save  the  comment  document   •  Set  at  the  id   f1e62   client.set( f1e62 ,{!   !   ! create a new      "type":  "comment",   ! !      "about_id”:"beer_Enlightened_Black_Ale",   document !      "user_id":  525,   !      "text":  "tastes  like  college!",     !      "updated":  "2010-­‐07-­‐22  20:00:20"   {   !        "id":  "f1e62"   ! }   });! 20  
  • 21. Link  between  comments  and  beers     {          "type":  "comment",   {        "about_id":  "beer_Enlightened_Black_Ale",        "brewery":  "New  Belgium  Brewing",   link to      "user_id":  525,        "name":  "1554  Enlightened  Black  Ale",   beer      "text":  "tastes  like  college!",        "abv":  5.5,        "updated":  "2010-­‐07-­‐22  20:00:20"        "descrip8on":  "Born  of  a  flood...",   }        "category":  "Belgian  and  French  Ale",        "style":  "Other  Belgian-­‐Style  Ales",          "updated":  "2010-­‐07-­‐22  20:00:20",       ra8ngs  :  {           525  :  5,   {        "id":  "f1e62"           30  :  4,           1044  :  2    },   }       comment_ids  :  [             f1e62 ,   link to           6ad8c        ]   comments }     21  
  • 22. How  to:  look  up  comments  from  a  beer   •  SERIALIZED  LOOP     beer = client.get( beer:A_cold_one );! beer.comment_ids.each { |id|! comments.push(client.get(id));! }! •  FAST  MULTI-­‐KEY  LOOKUP   beer = client.get( beer:A_cold_one );! comments = client.multiGet(beer.comment_ids)! ! •  ASYNC  VIEW  QUERY   comments = client.query( myapp , by_comment_on ,! {:key => beer:A_cold_one });! ! figure  hCp://www.ibm.com/developerworks/webservices/library/ws-­‐sdoarch/   22  
  • 23. How  to:  add  a  ra8ng  to  a  beer   •  Other  users  are  ra8ngs  beers  also,  so  we  use  a  CAS  update   –  we  don t  want  to  accidentally  overwrite  another  users  ra8ng  that  is  being  saved  at  the   same  8me  as  ours   •  Best  prac8ce  is  to  use  a  lambda  so  the  client  can  retry   cb.cas("mykey") do |doc| ! doc["ratings"][current_user.id] = my_rating doc! end! ! Actor  1   Actor  2   Success   CAS  mismatch   &  retry   Couchbase  Server   23  
  • 24. Object  Graph  With  Shared  Interac8ve  Updates   •  Challenge:  higher  level  data  structures   •  Objects  shared  across  mul8ple  users   •  Mixed  object  sets  (upda8ng  some  private  and  some   shared  objects)   figure  hCp://www.ibm.com/developerworks/webservices/library/ws-­‐sdoarch/   24  
  • 25. Get  With  Lock  (GETL)   •  O{en  referred  to  as   GETL   •  Pessimis8c  concurrency  control   •  Locks  have  a  short  TTL   •  Locks  released  with  CAS  opera8ons   •  Useful  when  working  with  object  graphs   25  
  • 26. Ques8ons?   26   2