How-to NoSQL Webinar - Couchbase 102 - SDK Operations


Published on

In Couchbase 102, you will learn the fundamentals of writing applications for Couchbase Server. This webinar will talk about about Couchbase’s capabilities in the context of some real use cases. Then it will demonstrate the fundamentals behind an application from demonstration to how specific application features are implemented. You will walk away with a good understanding of how developers are able to build easily scalable, consistent high performance web applications.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • (Internal Notes)
    Shifting Gears – lets talk about the primary considerations in choosing a NoSQL database.

    Introduce these 4 considerations explain why they are important to an Architect or Developer

    Does the customer agree?
  • the general case ... a full dinner!
    what is your user interaction flow... chef vs patron vs waiter. support all 3.?
    which are the most performance critical sections?
    publishing the evenings menu is OK to take a few seconds,
    but marking an item as out of stock needs to be fast
    waiter inputting orders needs to be fast, need latest data always
    customer browsing menu is OK to see a few seconds old version
  • why would you use a lock?
    assuming all your operations are idempotent: ONLY when the cost of CAS failure is greater than the cost of setting the lock.
    locking is only an optimization, provides no transactional boundaries.
  • How-to NoSQL Webinar - Couchbase 102 - SDK Operations

    1. 1. How-to NoSQL Couchbase 102 - SDK Operations Matt Ingenthron – Director, Developer Solutions Don Pinto – Product Manager, Developer Products
    2. 2. Introduction
    3. 3. Agenda • Couchbase Capabilities and Use Cases • Demo! • Couchbase Operations • Questions • Next Steps
    4. 4. Couchbase Server Has Easy Scalability Consistent High Performance Flexible Data Model Always On 24x7x365 Grow cluster without application changes, without downtime when needed Always awesome experience for your application users The sun never sets on the Internet, your application needs the database to always serve data Keep developers productive and allow fast and easy addition of new features JSON JSON JSON JSONJSON PERFORMANCE
    5. 5. Web Server Application Server Database In the beginning… Terminate connections, handle static content requests. Execute domain specific application logic, frequently in the context of a user session. Be the persistent store behind the data model defined at the application.
    6. 6. Web Server(s) Application Server(s) Database Building Next Generation
    7. 7. Web/App Server(s) Database … And the Next
    8. 8. Web/App Server(s) Database … And the Next Caching
    9. 9. Web/App Server(s) Database … And the Next Caching Writes Reads Reads Couchbase Cluster Node Node Node Node
    10. 10. Session Store Use Case
    11. 11. Session Store • Extremely fast access to session data using unique session ID • Easy scalability to handle fast growing number of users and user-generated data • Always-on functionality for global user base Application characteristic Use Case • Session values or Cookies (stored as key-value pairs) • Examples include: items in a shopping cart, flights selected, search results, etc. Data stored in Couchbase?
    12. 12. Globally Distributed User Profile Store Use Case
    13. 13. e enim nec felis rhoncus, ac volutpat magna blandit. Nunc facilisis turpis eget dolor mollis, id tincidunt dui mattis. Nunc sodales elementum turpis, vel interdum ante congue quis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.Aliquam erat volutpat. Nullam suscipit diam nec tortor pharetra, vitae adipiscing dolor pretium. Integer ac porta tortor. Vestibulum imperdiet quam laoreet nisl scelerisque, a tempus tortor tincidunt. Mauris suscipit dui ac urna dignissim, vitae aliquet velit convallis. Phasellus lobortis felis eu magna vulputate dapibus. Ut ornareut quam a vulputat ullam et dui odio. Nulla pharetra, velit ac convallis semper, dolor turpis porta nunc, in egestas mauris leo a nisi. Pellentesque fringilla sagittis magna vitae imperdiet. Mauris ac leo ut tellus aliquet interdum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nunc cursus odio sit amet elit mollis, et sollicitudin lacus accumsan.Nulla facilisi. Fusce et vehicula sem. Curabitur interdum vestibulum nulla id accumsan.Integer ut tortor in ligula semper vehicula. Vestibulum ut nibh ultrices, venenatis metus at, adipiscing ipsum. Donec quis consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec a diam tempus, aliquet ipsum eu, vestibulum sapien. Donec eleifend lectus sit amet luctus facilisis.Morbi porttitor, orci sit amet placerat tempus, nisi justo dictum augue, ac dignissim elit enim eget dolor. Praesent pulvinar ipsum arcu,eu posuere eros luctus nec. Vestibulum odio eros, ultrices non metus sit amet, tristique malesuada augue. Pellentesque lacinia dolor nec diam eleifend mollis. Vestibulum sit amet ultrices diam. Aliquam lacinia accumsan eros id hendrerit. Cras placeratlaoreet urna scelerisque rutrum. Duis ornare mi ac augue varius, sit amet accumsan leo lacinia. Vivamus nec egestas neque. Quisque interdum enim molestie urn. turpis eget dolor mollis, id tincidunt dui mattis. Nunc sodales elementum turpis, vel interdum ante congue quis. Pellentesque habitant morbi tristique senectus et netus et malesuada Welcome back Laura! You have 3 items in your shopping cart waiting for you. LOGIN ID: PASS: Globally Distributed User Profile Store • Extremely fast access to individual profiles • Always online system as multiple applications access user profiles • Flexibility to add and update user attributes • Easy scalability to handle fast growing number of users • User profile with unique ID • User setting / preferences • User’s network • User application state Data stored in Couchbase? Application characteristic Use Case Laura930 ********
    14. 14. Data Aggregation • Flexibility to store any kind of content • Flexibility to handle schema changes • Full-text Search across data set • High speed data ingestion • Scales horizontally as more content gets added to the system • Social media feeds: Twitter, Facebook, LinkedIn • Blogs, news, press articles • Data service feeds: Hoovers, Reuters • Data form other systems Data stored in Couchbase? Application characteristic Use Case in F t NEWS Blog
    15. 15. Questions?
    16. 16. Demo and Core Operations
    17. 17. Beer Trail Application Brewery Beers 1 .. N
    18. 18. Brewery Document Type is “brewery” Where is it on the map Name of the brewery ID of the brewery
    19. 19. Beer Document Type is “beer” Name of the beer Alcohol by volume Brewery ID ID of the beer
    20. 20. Modeling User Trails • Can represent rich data in JSON including arrays • Can modify schema on the fly, and Documents of a specific "type" can vary in schema Couchbase { “type": "User", "name": “Don Pinto", "email": “", “trail_history“: [ {“brewery_id": "olde_peninsula_brewpub_and_rest aurant", “beers_tasted": ["olde_peninsula_brewpu b_and_restaurant- 1_2_3_ale“, "olde_peninsula_brewpub _and_restaurant- 4_5_6_ale“]} ] } Trail history can be modeled in the user document or if it grows too large, in a separate trail document.
    21. 21. Working with application objects
    22. 22. Look up a beer or brewery Lookup by name Lookup by brewery id Lookups are best accomplished using key-value access
    23. 23. Listing all breweries and beers Emits brewery names Emits beer names JAVA CODE USING VIEWS IN COUCHBASE
    24. 24. Modifying a document beer, brewery or user • Use GSON to serialize Java POJO objects to JSON - Java classes must implement serializable
    25. 25. Deleting a brewery or beer • Delete is an async operation - Returns an OperationFuture that can be blocked through the get method • If the document does not exist - The OperationFuture returns false • If the operation succeeds - Couchbase Server lazily deletes that document from disk
    26. 26. Couchbase Basic Operations • 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
    27. 27. Atomic counters Atomic Counters are a special structure in Couchbase, they are executed 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
    28. 28. Making the app more interactive
    29. 29. Adding ratings and comments link to comments
    30. 30. • Set at the id “f1e62” "type": "comment", "about_id": "beer_Enlightened_Black_Ale", "user_id": 525, "text": "tastes like college!", "updated": "2010-07-22 20:00:20" client.set(“f1e62”,{ }); create a new document { "id": "f1e62" } Do it: Save the comment document But, multiple users can update this at the same time How to guarantee atomic updates with concurrent writes?
    31. 31. How to: Add a review and rating • Use a compare-and-swap (CAS) update - Don’t want to accidentally overwrite another users review comments and score that is being saved at the same time as ours Giving it a 5 “Nice flavor” 2 from me “Its bitter” Time T1 Time T2 User 1 User 2 Get CAS Version (User 1) Get CAS Version (User 2) JSON Beer Document CAS = 0 JSON Beer Document CAS = 0 1 Time T3 JSON Beer Document CAS = 1 2 Time T4 CAS succeeds for user 1 Fails for user 2 User 2 retries CAS succeeds for user 2
    32. 32. CAS Explained
    33. 33. Object Graph With Shared Interactive Updates 3 • Challenge: higher level data structures • Objects shared across multiple users • Mixed object sets (updating some private and some shared objects)
    34. 34. 3 Get With Lock (GETL) • Locks have a short TTL • Locks released with CAS operations • Useful when working with object graphs
    35. 35. Storing Items with Durability Requirements • Un-blocked when it has been written to disk in active location • Un-blocked when it has been written to a replica(s) • Un-blocked when it has been written to replica(s) disk • Durability Requirements when mutating data - set/add/replace("mykey", 0, value, PersistTo.MASTER, ReplicateTo.ONE) - maximum paranoia: set/add/replace("mykey", 0, value, PersistTo.FOUR, ReplicateTo.THREE) • Durability Requirements for replication only - set/add/replace("mykey", 0, value, ReplicateTo.ONE)
    36. 36. Blocking Wait Managed Cache Persistence Layer Durability PersistTo
    37. 37. Blocking Wait Managed Cache Persistence Layer Durability ReplicateTo
    38. 38. Questions?
    39. 39. Resources • Getting the SDKs and checking out the tutorial for each SDK - • Java Tutorial App Shown Earlier - Official SDKs in Python Ruby
    40. 40. Where to go Next • Attend the 103 webinar - June 14 – Couchbase-103-June14.html • Sign up for training - Developing – June 17 – New York City Administration – Jun 24 – Chicago Developing – June 24 – London • Join us at Couchbase Live [NYC] June 3, 2014
    41. 41. Thanks! Matt Ingenthron – – @ingenthr Don Pinto – – @NoSQLDon