• Share
  • Email
  • Embed
  • Like
  • Private Content
Getting Started with Couchbase App Development:
 

Getting Started with Couchbase App Development:

on

  • 1,427 views

 

Statistics

Views

Total Views
1,427
Views on SlideShare
986
Embed Views
441

Actions

Likes
4
Downloads
45
Comments
0

3 Embeds 441

http://www.couchbase.com 438
https://duckduckgo.com 2
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Most of you are probably familiar with the table layout. A table is defined with a set of column. And each record in the table conforms to the schema. If you wish to capture different data in the future, the table schema must be changed using the alter table statement. \n\nTypically data is normalized in the 3rd normal form reduce duplication. Large tables are split into smaller tables.using foreign keys \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • Example. \n\nNormalized schema \n2 tables \nFk connects the two. \nTo get information about a specific error, you will perform and join across the two tables \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • this could be the ruby form POST example\n
  • this could be the ruby form POST example\n
  • this could be the ruby form POST example\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Getting Started with Couchbase App Development: Getting Started with Couchbase App Development: Presentation Transcript

  • Developing with Couchbase I Jasdeep Jaitla Technical Evangelist email: twitter: @scalabl3jasdeep@couchbase.com
  • Developing with Couchbase I Jasdeep Jaitla Technical Evangelist email: twitter: @scalabl3jasdeep@couchbase.com
  • Developing with Couchbase Series www.couchbase.com/webinars
  • Presentation Summary• Setting Up Your Development Environment• Quick Server Architecture Overview• Intro to JSON Documents• Thinking in NoSQL• Intro to Couchbase Operations• Modeling & Agile Development
  • SETTING UP TO DEVELOP
  • Install Couchbase Server ✴ 2.0 www.couchbase.com/couchbase-server/beta OR, for the Latest 2.0 Build ✴ www.couchbase.com/download ✴ select 2.0.0 recent builds in dropdownUbuntuRedHatMac OS XWindows
  • Install Couchbase Server ✴ 2.0 www.couchbase.com/couchbase-server/beta OR, for the Latest 2.0 Build ✴ www.couchbase.com/download ✴ select 2.0.0 recent builds in dropdownUbuntuRedHat select 2.0.0 recent buildsMac OS XWindows
  • Install Couchbase Server ✴ 2.0 www.couchbase.com/couchbase-server/beta OR, for the Latest 2.0 Build ✴ www.couchbase.com/download ✴ select 2.0.0 recent builds in dropdownUbuntuRedHatMac OS XWindows
  • Install Couchbase Server ✴ 2.0 www.couchbase.com/couchbase-server/beta OR, for the Latest 2.0 Build ✴ www.couchbase.com/download ✴ select 2.0.0 recent builds in dropdownUbuntuRedHatMac OS XWindows
  • Official SDKswww.couchbase.com/develop Community SDKs
  • Official SDKs Ruby Pythonwww.couchbase.com/develop Community SDKs
  • Official SDKs Ruby Pythonwww.couchbase.com/develop Community SDKs Go Clojure
  • Official SDKsRuby libcouchbase Clojure Python www.couchbase.com/develop Go
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKs o n necti co n mak eCouchbase App Server
  • Smart Client SDKs n ctio o nne ma ke c logy topo r ec eiveCouchbase App Server
  • Smart Client SDKs po logy o c ei ve t reCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKs CouchbaseCouchbase Topology App Server Update
  • Smart Client SDKs CouchbaseCouchbase Topology App Server Update
  • Smart Client SDKs CouchbaseCouchbase Topology App Server Update
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • Smart Client SDKsCouchbase App Server
  • JSON DOCUMENTS
  • Aggregate View of Data http://martinfowler.com/bliki/
  • What is an aggregate?When you need to retrieve data from RDBMS, youare "aggregating" or "denormalizing" the data foryour application through queries with joins, whereclauses and order by clauses.In Document Databases, instead of breaking datainto tables and foreign keys, you store theaggregate data together in JSON document(s).
  • Store and Retrieve Aggregates order::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 } }• Easier to Distribute Data• More Flexibility
  • Relational vs Document Model C1 C2 C3 C4 { JSON JSON } JSONRelational data model Document data model Highly-structured table Collection of complex documents with organization with rigidly- arbitrary, nested data formats and defined data formats and varying “record” format. record structure. 14
  • SQL Normalized Tables Users Addresses KEY First Last ZIP_ID ZIP_ID CITY STATE ZIP 1 Jasdeep Jaitla 2 1 DEN CO 30303 2 Joe Smith 2 2 MV CA 94040 3 Ali Dodson 2 3 CHI IL 60609 4 John Doe 3 4 NY NY 10010To get information about specific user, you perform a join across two tables 15
  • SQL Normalized Tables Users Addresses KEY First Last ZIP_ID ZIP_ID CITY STATE ZIP 1 Jasdeep Jaitla 2 1 DEN CO 30303 2 Joe Smith 2 2 MV CA 94040 3 Ali Dodson 2 3 CHI IL 60609 4 John Doe 3 4 NY NY 10010To get information about specific user, you perform a join across two tables 15
  • SQL Normalized Tables foreign key Users Addresses KEY First Last ZIP_ID ZIP_ID CITY STATE ZIP 1 Jasdeep Jaitla 2 1 DEN CO 30303 2 Joe Smith 2 2 MV CA 94040 3 Ali Dodson 2 3 CHI IL 60609 4 John Doe 3 4 NY NY 10010To get information about specific user, you perform a join across two tables 15
  • SQL Normalized Tables foreign key Users Addresses KEY First Last ZIP_ID ZIP_ID CITY STATE ZIP 1 Jasdeep Jaitla 2 1 DEN CO 30303 2 Joe Smith 2 2 MV CA 94040 3 Ali Dodson 2 3 CHI IL 60609 4 John Doe 3 4 NY NY 10010 To get information about specific user, you perform a join across two tablesSELECT * FROM Users u INNER JOIN Addresses a ON u.zip_id = a.zip_id WHERE key=1 15
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 303032 Joe Smith 2 2 SF CA 941033 Ali Dodson 2 3 CHI IL 606094 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 303032 Joe Smith 2 2 SF CA 941033 Ali Dodson 2 3 CHI IL 606094 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 3030323 Joe Ali Smith Dodson 2 2 + 2 3 SF CHI CA IL 94103 606094 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 3030323 Joe Ali Smith Dodson 2 2 + 2 3 SF SF CHI CA CA IL 94103 94103 606094 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 3030323 Joe Ali Smith Dodson 2 2 + 2 3 SF SF CHI CA CA IL 94103 94103 606094 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 3030323 Joe Ali Smith Dodson 2 2 + 2 3 SF SF CHI CA CA IL 94103 94103 60609 =4 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 30303  { “ID”: 1, + = “First”:2 Joe Smith 2 2 SF SF CA CA 94103 94103 “Jasdeep”, “Last”: “Jaitla”, “ZIP”: “94103”,3 Ali Dodson 2 3 CHI IL 60609 “CITY”: “SF”, “STATE”: “CA” JSON }4 John Doe 3 4 NY NY 10010 All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 30303  { “ID”: 1, + = “First”:2 Joe Smith 2 2 SF SF CA CA 94103 94103 “Jasdeep”, “Last”: “Jaitla”, “ZIP”: “94103”,3 Ali Dodson 2 3 CHI IL 60609 “CITY”: “SF”, “STATE”: “CA” JSON }4 John Doe 3 4 NY NY 10010 Document Data is an Aggregate All data in a single document 16
  • Documents are Aggregates Users AddressesKEY First Last ZIP_ID ZIP_ID CITY STATE ZIP1 Jasdeep Jaitla 2 1 DEN CO 30303  { “ID”: 1, + = “First”:2 Joe Smith 2 2 SF SF CA CA 94103 94103 “Jasdeep”, “Last”: “Jaitla”, “ZIP”: “94103”,3 Ali Dodson 2 3 CHI IL 60609 “CITY”: “SF”, “STATE”: “CA” JSON }4 John Doe 3 4 NY NY 10010 Document Data is an Aggregate All data in a single document couchbase.get(“user::1”) 16
  • JSON Document Structure meta {Meta Information “id”: “u::jasdeep@couchbase.com”, Including Key “rev”: “1-0002bce0000000000”, “flags”: 0, “expiration”: 0,All Keys Unique “type”: “json”and Kept in RAM } document { “uid”: 123456,Document Value “firstname”: “jasdeep”, “lastname”: “Jaitla”, “age”: 22, Most Recent In “favorite_colors”: [“blue”, “black”],Ram And Persisted “email”: “jasdeep@couchbase.com” To Disk }
  • Document Keys Keys have to be unique in a Bucket (database) which acts as a namespace.Keys tend to have two categories:human-readable and random generatedHuman readable keys tend toward uniquedescriptors:email addresses, social media id’s, phonenumbers, blog post titles, usernames, sku’s, etc.
  • Objects Serialized to JSON andUser Object Back u::jasdeep@couchbase.com { set(string uid “uid”: 123456,string firstname “firstname”: “jasdeep”,string lastname “lastname”: “Jaitla”, “age”: 22,int age “favorite_colors”: [“blue”,array favorite_color “black”], s “email”:string emailUser u::jasdeep@couchbase.com get(string uid { “uid”: 123456,string firstname “firstname”: “jasdeep”,string lastname “lastname”: “Jaitla”, “age”: 22,int age “favorite_colors”: [“blue”,array favorite_color “black”], s “email”:string email
  • JSON only? Nope! Couchbase can store straight strings,binary blobs, JSON Documents and a special structure called an Atomic Counter (a positive integer value with its own special operations). Maximum size of a Document is 20MB.
  • Indexing & QueryingCouchbase 2.0’s Views (Distributed Map/Reduce) and Elastic Search Integration enable different types of Indexing, Querying and Searching for Documents We cover the fundamentals of this in the upcomingwebinars, but you can also refer to our previous webinars on the subjects: Indexing/Querying Incremental Map Reduce for Real-Time Analytics Full Text Search Integration (Elastic Search)
  • COUCHBASEOPERATIONS
  • •get (key) – Retrieve a document•set (key, value) – Store a document, overwrites if exists•add (key, value) – Store a document, error/exception if exists•replace (key, value) – Store a document, error/exception if doesn’t exist•cas (key, value, cas) – Compare and swap, mutate document only if it hasn’t changed while executing this operation
  • Atomic Counter Operations These operations are always executed in order atomically.• set (key, value) – Use set to initialize 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
  • Mental Adjustments• In SQL we tend to want to avoid hitting the database as much as possible – Even with caching and indexing tricks, and massive improvements over the years, SQL still gets bogged down by complex joins and huge indexes• In Couchbase, get’s and set’s are so fast they are trivial, and not bottlenecks, this is hard for many people to accept at first; Multiple get statements are commonplace, don’t avoid it!
  • EXAMPLE
  • Ruby Example# example.rb # user.rbrequire “./user.rb” require “rubygems” require “couchbase”u1 = User.new({ :email => “jasdeep@scalabl3.com”, class User :name => “Jasdeep Jaitla”, attr_accessor :name, :email, :title, :title => “Scalability Sherpa”, :twitter :twitter => “@scalabl3 }) def initialize(attr = {}) attr.each do |name, value|u1.save setter = "#{name}=" next unless respond_to?(setter) send(setter, value) end end def save c = Couchbase.bucket c. set(@email.downcase, self.to_json) end end
  • Add Lookup Class Method# example.rb # user.rbrequire “./user.rb” require “rubygems” require “couchbase”u1 = User.new({ :email => “jasdeep@scalabl3.com”, class User :name => “Jasdeep Jaitla”, :title => “Scalability Sherpa”, attr_accessor :name, :email, :title, :twitter => “@scalabl3 :twitter }) def initialize(attr = {}) ... endu1.save def saveu1 = User.find_by_email(“jasdeep@scalabl3.com”) c = Couchbase.bucketif u1 c.set(@email.downcase, self.to_json) puts “User Found!” end puts u1.inspectelse def self.find_by_email(email) puts “User Not Registered!”end c = Couchbase.bucket doc = c.get(email.downcase) return doc ? User.new(doc) : nil end end
  • Agile Model Development# example.rb # user.rbrequire “./user.rb” require “rubygems” require “couchbase”u1 = User.find_by_email(“jasdeep@scalabl3.com”) class Userif u1 u1.fb_id = “682829292” attr_accessor :name, :email, :title, u1.fb_token = “f02jdjd020d8373730djd02” :twitter u1.save attr_accessor :fb_id, :fb_tokenelse # create user def initialize(attr = {}) ... endend def save ... end def self.find_by_email(email) c = Couchbase.bucket doc = c.get(email.downcase) return doc ? User.new(doc) : nil end end
  • MULTIPLEDOCUMENTS
  • • User profile BLOG •• Blog Post Object – Contains the Content (ID, Title, Body Text, Author)• Blog Comment – Comments from other users • Option 1 - Keep it with Blog Document • Option 2 - Separate it Out
  • Single Document {Blog Post Object “id”: “scalabl3_Hello_World”,string id “author”: “scalabl3”,string author “type”: “post”string type “title”: “Hello World”, “format”: “markdown”,string title “body”: “Hello from [Couchbase](http://string format couchbase.com).”,string body “html”: “<p>Hello from <a href=“http: …,string html “comments”: [array comments {“format”: “markdown”, “body”:”Awesome post!”}, {“format”: “markdown”, “body”:”Like it.” } ] }
  • Multiple Documents {Blog Post Object “id”: “scalabl3_Hello_World”,string id “author”: “scalabl3”,string author “type”: “post” “title”: “Hello World”,string type “format”: “markdown”,string title “body”: “Hello from [Couchbase](http://string format couchbase.com).”, “html”: “<p>Hello from <a href=“http: …,string body “num_comments”: 2string html }int comments { “id”: “scalabl3_Hello_World::1”,Comment Object “format”: “markdown”, “body”: “Awesome post!”string format }string body {int id “id”: “scalabl3_Hello_World::2”, “format”: “markdown”, “body”: “Love It!” }
  • Multiple Documents {Blog Post Object “id”: “scalabl3_Hello_World”,string id “author”: “scalabl3”,string author “type”: “post” “title”: “Hello World”,string type “format”: “markdown”,string title “body”: “Hello from [Couchbase](http://string format couchbase.com).”, “html”: “<p>Hello from <a href=“http: …,string body }string htmlint comments { “id”: “scalabl3_Hello_World::comments”, 2 } { “id”: “scalabl3_Hello_World::1”,Comment Object “format”: “markdown”, “body”: “Awesome post!”string format }string body {int id “id”: “scalabl3_Hello_World::2”, “format”: “markdown”, “body”: “Love It!” }
  • Model Structures USER Couchbase instance variables JSON Couchbase JSON USERinstance variables JSON Couchbase Array Data Couchbase Hash Data Set/List Data JSON JSON
  • eCommerce Model USER JSON instance variables shopping_cartsORDER ORDER JSON Couchbase ordersinstance variables instance variables statistics JSON JSON JSON JSON JSON ShoppingCart JSON JSON JSON instance variables JSON CartItems JSON JSON JSON PRODUCT PRODUCT CartItems JSON CartItems JSON instance variables JSON instance variables instance variables instance variables
  • A Few Tips for Single vs Multiple• If an object is pretty simple, generally a Single Document is best• Use Multiple Documents when it’s advantageous to do so - Simpler Code - Simpler Model - Reduce Document Bloating• Generally if you have large or limitless lists, it’s best to use a Multiple Document Scheme• Atomic Counters are great for keeping track of numerical information that changes a lot, like points, counts, stats, etc.• Atomic Counters can be used to create Key-Value Patterns
  • Summary• Couchbase • Client SDKs for Every Major -Is a Document Database Language -Has Easy Scalability • Modeling -Consistent High -Can Be Simple 1:1 Mappings Performance -Can Involve Multiple -Always On 24/7/365 Documents 1:n• Couchbase Operations -Can Have Relationships without Joins -Operations are lightning fast -You don’t have to avoid multiple gets, they’re fast
  • I’m Excited to See What You Build, Thanks For Watching! Q&ACouchbase Docs Contact me on Twitterwww.couchbase.com/docs/index-full.html @scalabl3Couchbase Forums Contact me by Emailwww.couchbase.com/forums jasdeep@couchbase.comIRC Learn More About Design#couchbase Patterns#libcouchbase CouchbaseModels.com Setting up for Ruby on Rails CouchbaseOnRails.com Coming Soon... CouchbaseOnNode.com