developing apps with couchbase
TRANSCRIPT
Friday, December 7, 12
Technical Evangelist
twi0er: @scalabl3email: [email protected]
Jasdeep Jaitla
Developing Apps with Couchbase
Friday, December 7, 12
Technical Evangelist
twi0er: @scalabl3email: [email protected]
Jasdeep Jaitla
Developing Apps with Couchbase
Friday, December 7, 12
Friday, December 7, 12
SETTING UP TO DEVELOP
Friday, December 7, 12
Install Couchbase Server 2.0✴ www.couchbase.com/couchbase-‐server/beta
✴ www.couchbase.com/download
✴ select 2.0.0 recent builds in dropdown
OR, for the Latest 2.0 Build
Ubuntu
RedHat
Mac OS X
WindowsFriday, December 7, 12
Install Couchbase Server 2.0✴ www.couchbase.com/couchbase-‐server/beta
✴ www.couchbase.com/download
✴ select 2.0.0 recent builds in dropdown
OR, for the Latest 2.0 Build
select 2.0.0 recent builds
Ubuntu
RedHat
Mac OS X
WindowsFriday, December 7, 12
Install Couchbase Server 2.0✴ www.couchbase.com/couchbase-‐server/beta
✴ www.couchbase.com/download
✴ select 2.0.0 recent builds in dropdown
OR, for the Latest 2.0 Build
Ubuntu
RedHat
Mac OS X
WindowsFriday, December 7, 12
Install Couchbase Server 2.0✴ www.couchbase.com/couchbase-‐server/beta
✴ www.couchbase.com/download
✴ select 2.0.0 recent builds in dropdown
OR, for the Latest 2.0 Build
Ubuntu
RedHat
Mac OS X
WindowsFriday, December 7, 12
Official SDKs
Community SDKs
www.couchbase.com/develop
Go
Friday, December 7, 12
Official SDKs
Community SDKs
www.couchbase.com/develop
PythonRuby
Go
Friday, December 7, 12
Official SDKs
Community SDKs
www.couchbase.com/develop
PythonRuby
Clojure Go
Friday, December 7, 12
Official SDKs
www.couchbase.com/develop
Clojure
Python
Ruby
libcouchbase
Go
Friday, December 7, 12
Friday, December 7, 12
JSON DOCUMENTS
Friday, December 7, 12
Aggregate View of Data
h0p://marWnfowler.com/bliki/AggregateOrientedDatabase.html
Friday, December 7, 12
Store and Retrieve Aggregates
• Easier to Distribute Data• More Flexibility• Reduced Latency
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 }}
Friday, December 7, 12
Documents are Aggregates
10
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
1 Jasdeep Jaitla
94103CASF
Friday, December 7, 12
Documents are Aggregates
10
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
SF 94103CA
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
SF 94103CA
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
=1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
SF 94103CA
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
{ “ID”: 1, “First”: “Jasdeep”, “Last”: “Jaitla”, “ZIP”: “94103”, “CITY”: “SF”, “STATE”: “CA” } JSON
=1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
SF 94103CA
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
{ “ID”: 1, “First”: “Jasdeep”, “Last”: “Jaitla”, “ZIP”: “94103”, “CITY”: “SF”, “STATE”: “CA” } JSON
=
Document Data is an Aggregate
1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
SF 94103CA
Friday, December 7, 12
Documents are Aggregates
10
+
Addresses
1 DEN 30303CO
2
3 CHI 60609IL
4 NY 10010NY
ZIP_ID CITY ZIPSTATE
Users
KEY First ZIP_IDLast
2
2 Joe 2Smith
3 Ali 2Dodson
4 John 3Doe
All data in a single document
{ “ID”: 1, “First”: “Jasdeep”, “Last”: “Jaitla”, “ZIP”: “94103”, “CITY”: “SF”, “STATE”: “CA” } JSON
=
couchbase.get(“user::1”)
Document Data is an Aggregate
1 Jasdeep Jaitla
94103CASF
1 Jasdeep Jaitla
SF 94103CA
Friday, December 7, 12
JSON Document Structuremeta{
“id”: “u::[email protected]”,“rev”: “1-‐0002bce0000000000”,“flags”: 0,“expira^on”: 0,“type”: “json”
}
document{
“uid”: 123456,“firstname”: “jasdeep”,“lastname”: “Jaitla”,“age”: 22,“favorite_colors”: [“blue”, “black”],“email”: “[email protected]”
}
Meta Informa^on Including Key
All Keys Unique and Kept in RAM
Document Value
Most Recent In Ram And Persisted To Disk
Friday, December 7, 12
Objects Serialized to JSON and Back User Objectstring uid
string firstname
string lastname
int age
array favorite_colors
string email
“uid”: 123456,“firstname”: “jasdeep”,“lastname”: “Jaitla”,“age”: 22,“favorite_colors”: [“blue”, “black”],“email”: “[email protected]”
}
User Objectstring uid
string firstname
string lastname
int age
array favorite_colors
string email
“uid”: 123456,“firstname”: “jasdeep”,“lastname”: “Jaitla”,“age”: 22,“favorite_colors”: [“blue”, “black”],“email”: “[email protected]”
}
set()
get()
Friday, December 7, 12
Model Structures
JSON Couchbase
USER
instance variablesCouchbase
USER
instance variables
Array Data
Hash Data
Set/List Data
JSON
JSON
JSON
Couchbase
JSON
Couchbase
Friday, December 7, 12
eCommerce Model
JSONJSONJSONJSON
USER
instance variables
shopping_carts
statistics
JSON
JSON
JSON
ShoppingCart
instance variables
CartItems
JSON
CartItems
instance variables
JSONJSON
JSONCartItems
instance variables
JSONJSONJSON
JSONJSONJSON
CouchbaseORDER
instance variables
ORDER
instance variables
PRODUCT
instance variables
PRODUCT
instance variables
JSONJSONJSONJSON
orders
Friday, December 7, 12
Friday, December 7, 12
RAPID APP
Friday, December 7, 12
class User < ModelBase # doctype value fattr :doctype, :default => self.to_s.camelize fattr :uid fattr :is_netwerkd, :default => false # facebook stuff fattr :has_facebook, :default => false fattrs :fb_id, :fb_firstname, :fb_lastname, :fb_fullname, :fb_nickname, :fb_username, :fb_gender,:fb_email, :fb_hometown, :fb_location, :fb_img_square, :fb_img_small, :fb_img_normal, :fb_img_large, :fb_access_token, :fb_token_expires # twitter stuff fattr :has_twitter, :default => false fattrs :tw_id, :tw_handle, :tw_nickname, :tw_fullname, :tw_location, :tw_img, :tw_desc, :tw_following_count, :tw_followers_count, :tw_tweets_count, :tw_member_since, :tw_access_token, :tw_access_secret
# linkedin stuff fattr :has_linkedin, :default => false fattrs :li_id, :li_firstname, :li_lastname, :li_fullname, :li_headline, :li_email, :li_img, :li_skills, :li_industry, :li_connections_count, :li_access_token, :li_access_secret, :li_public_url
Modeling Is Fun & Easy
I didn’t have to waste hours upon hours making columns, tables, foreign keys, and picking column data types.
Friday, December 7, 12
Consolidated Document{"doctype"=>"User", "uid"=>1, "is_netwerkd"=>true, "has_facebook"=>true, "fb_id"=>"661111011", "fb_firstname"=>"Jasdeep", "fb_lastname"=>"Jaitla", "fb_fullname"=>"Jasdeep Jaitla", "fb_nickname"=>"jasdeep.jaitla", "fb_username"=>"jasdeep.jaitla", "fb_gender"=>"male", "fb_email"=>"[email protected]", "fb_hometown"=> {"id"=>"110184922344060", "name"=>"Washington, District of Columbia"}, "fb_location"=>{"id"=>"114952118516947", "name"=>"San Francisco, California"}, "fb_img_square"=>"http://graph.facebook.com/661111011/picture?type=square", "fb_img_small"=>"http://graph.facebook.com/661111011/picture?type=small", "fb_img_normal"=>"http://graph.facebook.com/661111011/picture?type=normal", "fb_img_large"=>"http://graph.facebook.com/661111011/picture?type=large", "fb_access_token"=> "AAACa7POXlM4BAC0yPc4NFlPGqTGdZANFKEYo2yucXAQSLXtUfBHPCHNVKWXcosm4D4uWk0OJkWWqjkbo9LZAxR6FrIKf2t2eCU3O884wZDZD", "fb_token_expires"=>1359369670, "has_twitter"=>true, "tw_id"=>"573365281", "tw_handle"=>"scalabl3", "tw_nickname"=>nil, "tw_fullname"=>"Scalabl3", "tw_location"=>"San Francisco", "tw_img"=> "http://a0.twimg.com/profile_images/2403799460/1i9qyazuxw9gm8cenceh_normal.jpeg", "tw_desc"=> "Creating Scalable applications and social games for the next millenium, yeah I'm talkin the 3000's.", "tw_following_count"=>322, "tw_followers_count"=>180, "tw_tweets_count"=>427, "tw_member_since"=>"Mon May 07 06:45:14 +0000 2012", "tw_access_token"=>"573365281-‐6kXHB5eCiOXFdJqWyFKV8lWHXLrTqxh01eERlvRZ", "tw_access_secret"=>"UyMDizWszkpdhnqRoehJ8smU6Jr1I4gd9uYATuOQnoU", "has_linkedin"=>true, "li_id"=>"G_Auyd8JsP", "li_firstname"=>"Jasdeep", "li_lastname"=>"Jaitla, MBA", "li_fullname"=>"Jasdeep Jaitla, MBA", "li_headline"=>"Scalability Sherpa / Technical Evangelist at Couchbase", "li_email"=>"[email protected]", "li_img"=> "http://m3.licdn.com/mpr/mprx/0_9fXpR8EwYXj-‐bqZTq7L7Ri0sp3VjwBJTNHr_RiDsibaDN1a3sdqrv_MN-‐2sGHK4Sc26GqkP3QJPe", "li_skills"=> ["Product Management", "Product Marketing", "Technical Management", "Strategy", "Screenwriting", "Leadership", "Team Building", "Photography", "Couchbase", "Neo4j", "Ruby", "Ruby on Rails", "Python", "Go", "Io", "Microsoft SQL Server", "MySQL", "Clojure", "Java", "JRuby"], "li_industry"=>"Internet", "li_connections_count"=>516, "li_access_token"=>"207dd456-‐f054-‐423f-‐90c3-‐319bdfb1efcc", "li_access_secret"=>"46912d4b-‐2540-‐425a-‐afc9-‐838b13ad4d65", "li_public_url"=>"http://www.linkedin.com/in/jasdeepjaitla"}
I got the Basic App Running in a few hours! Then added more features incrementally...
Friday, December 7, 12
Simplified OperaWons
def update_save raise "Cannot Save without UID (creation)" unless @uid replace_document(@docs[:id], to_hash) update_refs self end
couchbase.replace(“u::1”, hash_to_json)
Friday, December 7, 12
Recent Cool Things
Couchbase Couchbase
Cross Data Center Replication(XDCR)
XDCR >> Elastic Search
Elastic Search Cluster
Couchbase
XDCR >> Worker Cluster
Worker Cluster
Couchbase
Couchbase XDCR Receiver Endpoints
Filter by JSON or String Search
Beanstalkd Job Queue
Neo4J
Worker Worker Worker
Friday, December 7, 12
Q & A
Jasdeep Jaitla@scalabl3
Dip^ Borkar@dborkar
Friday, December 7, 12