Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

CouchConf Tokyo 2013_Getting Started with Couchbase App Development

706 views

Published on

  • Be the first to comment

  • Be the first to like this

CouchConf Tokyo 2013_Getting Started with Couchbase App Development

  1. 1. Getting Started withCouchbase App Development Matt Ingenthron Director, Developer Solutions
  2. 2. Who is Matt Ingenthron?• Matt has been working with Couchbase since the beginning.• Helped shape many of the features and architecture from experience of what was troublesome with previous large-scale web deployments.• Has a passion for helping make app development more simple and straightforward.• Currently leading the team in building out the right client interface into Couchbase and integration with higher level frameworks. 3
  3. 3. Agenda• Learn what it takes to get started and begin to build an application against Couchbase.• Lean how you work with a Document Database and what is different. Learn how you work with documents in Couchbase itself.• Gain an understanding of how fundamentally different approaches in Couchbase allow for your application to scale and consistently perform well. 4
  4. 4. GETTING STARTED 5
  5. 5. Where to Obtain CouchbaseDownload from Get a client fromcouchbase.com/download couchbase.com/developInstall via .rpm, .deb, .exe, or .app • Central place for clients, both officially supported and community driven. • Java, .NET, PHP, Ruby and C • Python, golang, JRuby, Erlang, etc. • Install using common tools such as Java’s Maven, Ruby’s gem, Ubuntu apt, etc. 6
  6. 6. Demo 7
  7. 7. PROGRAMMING MODEL 8
  8. 8. The Relational Approach to Storing Data Relational databases were not designed with clusters in mind, which is why people have cast around for an alternative. Storing aggregates as fundamental units makes a lot of sense for running on a cluster. http://martinfowler.com/bliki/AggregateOrientedDatabase.html 9
  9. 9. Document Database by Comparison 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 application programmers 10
  10. 10. Basics: Retrieve• get (key) – Retrieve a document• gets(key) – Retrieve a document and the CAS value associated with the object (more on this in a bit) 11
  11. 11. Basics: Create, Update, Delete• set (key, value) – Store a document, overwrites if exists• add (key, value) – Store a document, error/exception if it already exists• replace (key, value) – Store a document, error/exception if doesn’t exist• delete(key) – Delete the document from the systemAlso: new feature to allow applications to express durabilityrequirements: ReplicateTo.TWO, PersistTo.TWO 12
  12. 12. Atomic IntegersAtomic Counters are a special structure in Couchbase, they areexecuted in order and are Positive Integer Values•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 13
  13. 13. Simple Example in Ruby# example.rb # user.rbrequire “./user.rb” require “rubygems” require “couchbase”u1 = User.new({ :email => “michael.nitschinger@c…”, class User :name => “Michael Nitschinger”, attr_accessor :name, :email, :title, :twitter :title => “Developer Advocate”, :twitter => “@daschl” def initialize(attr = {})}) attr.each do |name, value| setter = "#{name}=”u1.save next unless respond_to?(setter) send(setter, value) end end def save client = Couchbase.bucket client.set(@email.downcase, self.to_json) end end 14
  14. 14. Extending Example with Accessor# example.rb # user.rbrequire “./user.rb” require “rubygems” require “couchbase”u1 = User.new({ :email => “michael.nitschinger@c…”, class User :name => “Michael Nitschinger”, attr_accessor :name, :email, :title, :twitter :title => “Developer Advocate”, :twitter => “@daschl”}) def initialize(attr = {}) ... endu1.save def save client = Couchbase.bucketu1 = User.find_by_email(“michael.nitschinger@c…”) client.set(@email.downcase, self.to_json) endif u1 puts “User Found!” puts u1.inspect def self.find_by_email(email)else client = Couchbase.bucket puts “User Not Registered!” doc = client.get(email.downcase)end return doc ? User.new(doc) : nil end end 15
  15. 15. Compare and Swap Optimistic Concurrency in a Distributed System# actors.rbc = Couchbase.bucketc.set(“mydoc”, { :myvalue => nil } Actor 1 Actor 2doc1, flags, cas = c.get(“mydoc”, :extended => true) Success CAS mismatch!doc2, flags, cas = c.get(“mydoc”, :extended => true)# Couchbase Serverc.set (“mydoc”, { “myvalue”: true }, :cas => cas)# will fail because cas has changedc.set (“mydoc”, { “myvalue”: true }, :cas => cas) 16
  16. 16. DIFFERENCES OF NOTE 17
  17. 17. Consistently Has High Performance Couchbase Ensures… • Responses are always fast • Even if a response can’t be serviced right away A Managed Cache Shift your Expectations: • No longer a need to avoid round-trips • No longer a need to avoid database requests for application speed 18
  18. 18. Scales Easily, Transparently• As an appliction developer, you think about interacting with the cluster – No longer a need to think about shards – No longer have to deploy and manage internal or external proxies to understand where the data is placed 19
  19. 19. Client Setup: Getting Cluster Configuration Cluster Configuration Couchbase Client over REST { … "bucketCapabilities": [ "touch", "sync", "couchapi" http://myserver:8091/pools ], "bucketCapabilitiesVer": "sync-1.0", "bucketType": ”couchbase", "name": "default", "nodeLocator": "vbucket", "nodes": [ …. 20
  20. 20. Client Setup: Getting Cluster Configuration Couchbase Client New Node Added to Cluster and Coming Online Couchbase Topology Update 21
  21. 21. Add Nodes to Cluster APP SERVER 1 APP SERVER 2 COUCHBASE Client Library COUCHBASE Client Library CLUSTER MAP CLUSTER MAP READ/WRITE/UPDATE READ/WRITE/UPDATE SERVER 1 SERVER 2 SERVER 3 SERVER 4 SERVER 5 • Two servers added One-click operation ACTIVE ACTIVE ACTIVE ACTIVE ACTIVE Doc 5 Doc Doc 4 Doc Doc 1 Doc • Docs automatically rebalanced across Doc 2 Doc Doc 7 Doc Doc 2 Doc cluster Even distribution of docs Minimum doc movement Doc 9 Doc Doc 8 Doc Doc 6 Doc • Cluster map updated REPLICA REPLICA REPLICA REPLICA REPLICA • App database Doc 4 Doc Doc 6 Doc Doc 7 Doc calls now distributed over larger number Doc 1 Doc Doc 3 Doc Doc 9 Doc of servers Doc 8 Doc Doc 2 Doc Doc 5 Doc COUCHBASE SERVER CLUSTER 22User Configured Replica Count = 1
  22. 22. In SummaryEasy to Get Started, Straightforward to UseDownload, install server. Binaries are available. Provisioning is fast through thebrowser and flexible with a REST interface. Install client using tools such as Java’smaven, Ruby’s gem, etc. Interact with simple verbs.Document Database, Simple ApproachWork with aggregates, usually JSON. Use simple operations to work with yourdata. Couchbase understands and is designed for distributed systems.Deployment of Applications Allow forScale, PerformanceNew approaches to storing and retrieving data in Couchbase give developers the ability toeasily scale up and make their applications perform. 23
  23. 23. Q&A 24
  24. 24. THANKS! 25
  25. 25. Image Attribution• Broken Glass: http://ajudgetocrush.deviantart.com/art/Broken-Glass- 151350225 26
  26. 26. 27

×