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.

I Have a NoSQL toaster - DC - August 2017

95 views

Published on

My toaster stores data without SQL and without tables. But making a choice based on what something doesn’t have isn’t terribly useful. “NoSQL” is an increasingly inaccurate catch-all term that covers a lot of different types of data storage. Let’s make more sense of this new breed of database management systems and go beyond the buzzword. In this session, the four main data models that make up the NoSQL movement will be covered: key-value, document, columnar and graph. How they differ and when you might want to use each one will be discussed.

This session will be looking at the whole ecosystem, with a more detailed focus on Couchbase, Cassandra, Riak KV, and Neo4j.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

I Have a NoSQL toaster - DC - August 2017

  1. 1. ©2017 Couchbase Inc. 2
  2. 2. ©2017 Couchbase Inc. 3 Where am I? • .NET DC User Group • https://www.meetup.com/dotnetdc/
  3. 3. ©2017 Couchbase Inc. 4 Who am I? • Matthew D. Groves • Developer Advocate for Couchbase • @mgroves onTwitter • Podcast and blog: http://crosscuttingconcerns.com • “I am not an expert, but I am an enthusiast.” – Alan Stevens
  4. 4. ©2017 Couchbase Inc. 5 SQL is the norm, right? https://commons.wikimedia.org/wiki/File:George_Wendt_at_the_41st_Emmy_Awards_cropped.jpg
  5. 5. ~3200 BC: invention of writing in Mesopotamia ~300 BC: Library of Alexandria ~1041AD: Movable type invented inChina 1450: Movable type invented in Europe 1822: Babbage’s paper on the application of difference engines 1943: Colossus, the first programmable digital computer 1957-1960: IBM SABRE, the first commercial use of a database 1970: EF Codd proposes the relational database model 1974: Ingres released 1979: Commercial launch of Oracle database 1988: Object databases appear 1989: Microsoft SQL Server version 1 1991: HTTP v0.9 1995: MySQL’s initial release 2005: CouchDB released 2006: Google’s BigTable paper 2007: Amazon’s Dynamo paper 2008-2009: The NoSQL Cambrian explosion: Riak, MongoDB,Cassandra, Redis 2010: Couchbase arrives on the scene
  6. 6. NoSQL isn’t a very useful term
  7. 7. ©2017 Couchbase Inc. 8 Scalable? https://commons.wikimedia.org/wiki/File:Dagwood_sandwich.jpg
  8. 8. ©2017 Couchbase Inc. 9 Easy? Flexible?
  9. 9. ©2017 Couchbase Inc. 10 ACID vs BASE? https://commons.wikimedia.org/wiki/File:PH_Scale.svg Atomic Consistent Isolated Durable Basic Availability Soft-state Eventual consistency
  10. 10. ©2017 Couchbase Inc. 11 Schema Schemaless https://en.wikipedia.org/wiki/File:Star-schema-example.png
  11. 11. ©2017 Couchbase Inc. 12 Normalized Denormalized https://commons.wikimedia.org/wiki/File:Frown.JPG
  12. 12. ©2017 Couchbase Inc. 13 First: Why NoSQL? https://www.flickr.com/photos/wonderlane/13067014944
  13. 13. ©2017 Couchbase Inc. 14 Round pegs, square holes http://www.timesofbook.com/2013/09/blobfish-image-gallery.html#.V6iXwbgrJhE
  14. 14. ©2017 Couchbase Inc. 15 Perhaps SQL is right for this project
  15. 15. ©2017 Couchbase Inc. 16 Scaling can be hard
  16. 16. ©2017 Couchbase Inc. 17
  17. 17. ©2017 Couchbase Inc. 18 Availability is hard
  18. 18. ©2017 Couchbase Inc. 19
  19. 19. ©2017 Couchbase Inc. 20 Schemas can be hard https://commons.wikimedia.org/wiki/File:MediaWiki_database_schema_1-17_(r82044).svg
  20. 20. ©2017 Couchbase Inc. 21 Types of NoSQL databases Document Key/Value Columnar Graph
  21. 21. ©2017 Couchbase Inc. 22 Convergence!
  22. 22. ©2017 Couchbase Inc. 23 Document
  23. 23. ©2017 Couchbase Inc. 25 What makes it a document database?
  24. 24. JSON XML BSON
  25. 25. ©2017 Couchbase Inc. 28 The document database understands the format of the document
  26. 26. ©2017 Couchbase Inc. 29 It can do server-side stuff
  27. 27. Buckets Documents N1QL
  28. 28. "ClientProductCode","Title","Quantity" "TShirtCBS","Couchbase logo t-shirt (small)",29 "TShirtCBM","Couchbase logo t-shirt (medium)",72 "TShirtCBL","Couchbase logo t-shirt (large)",34 "TShirtCBXL","Couchbase logo t-shirt (extra large)",12 "StickerCBLogo","Couchbase logo sticker",256 "PenCBLogo","Couchbase logo pen",365
  29. 29. class Program { private static IBucket _bucket; static void Main(string[] args) { SetupCouchbase(); LoadStockList(); ClusterHelper.Close(); } private static void SetupCouchbase() { ClientConfiguration config = new ClientConfiguration(); config.Servers = new List<Uri> {new Uri("couchbase://192.168.1.5") }; ClusterHelper.Initialize(config); _bucket = ClusterHelper.GetBucket("default"); } private static void LoadStockList() { var csv = new CsvReader(File.OpenText("swag.csv")); while (csv.Read()) { var record = csv.GetRecord<dynamic>(); var document = new Document<dynamic> { Id = record.ClientProductCode, Content = new { record.Title, record.Quantity } }; _bucket.Insert(document); Console.WriteLine($"Added document '{record.ClientProductCode}'"); } } }
  30. 30. private static void SetupCouchbase() { ClientConfiguration config = new ClientConfiguration(); config.Servers = new List<Uri> {new Uri("couchbase://localhost") }; ClusterHelper.Initialize(config); _bucket = ClusterHelper.GetBucket("default"); }
  31. 31. private static void LoadStockList() { var csv = new CsvReader(File.OpenText("swag.csv")); while (csv.Read()) { var record = csv.GetRecord<dynamic>(); var document = new Document<dynamic> { Id = record.ClientProductCode, Content = new { record.Title, record.Quantity } }; _bucket.Insert(document); Console.WriteLine($"Added document '{record.ClientProductCode}'"); } }
  32. 32. private static void GetDocument() { var doc = _bucket.Get<dynamic>("StickerCBLogo"); Console.WriteLine($"Document Key: {doc.Id}"); Console.WriteLine($"Title: {doc.Value.title}"); Console.WriteLine($"Quantity: {doc.Value.quantity}"); }
  33. 33. ©2017 Couchbase Inc. 38 Typical Document Database Core Operations • Upsert (aka set) • Inserts document if key doesn’t exist, replaces otherwise • Insert (aka add) • Inserts document, error if it already exists • Update (aka replace) • Updates document, error if it doesn’t exist • Delete • Get
  34. 34. ©2017 Couchbase Inc. 39 N1QL SELECT m.* FROM `default` m WHERE META(m).id = ‘StickerCBLogo’ SELECT m.* FROM `default` m WHERE m.quantity > 10
  35. 35. Great for Dev Scales Easily Consistently Fast SQL for NoSQL
  36. 36. ©2017 Couchbase Inc. 41
  37. 37. ©2017 Couchbase Inc. 42 Use cases for Document Databases • User profiles • Session stores • Content management • Others: http://info.couchbase.com/15Q1TopTenUC.html
  38. 38. ©2017 Couchbase Inc. 43 Key/Value Database
  39. 39. ©2017 Couchbase Inc. 45 Key-Value Databases In-memory caches and distributed data stores
  40. 40. ©2017 Couchbase Inc. 46 Doesn’t care what your data is (mostly) KEY1 { type: “json” } KEY2 <data type=“xml”></data> KEY3 Lorem ipsum … 00100101000100101 KEYN https://www.flickr.com/photos/dcmot/23168680069
  41. 41. Buckets Key-Value Pairs
  42. 42. ©2017 Couchbase Inc. 48 C# Riak private static void DoStuffWithRiak() { var cluster = RiakCluster.FromConfig("riakConfig"); var client = cluster.CreateClient(); var actor = new RiakObject("actors", "James Bond","Sean Connery"); client.Put(actor); var actorBackOut = client.Get("actors", "James Bond"); var str = System.Text.Encoding.UTF8.GetString(actorBackOut.Value.Value); Console.WriteLine($"Value: {str}"); }
  43. 43. ©2017 Couchbase Inc. 50 Introducing: Eventual Consistency!
  44. 44. ©2017 Couchbase Inc. 51 Eventual Consistency https://www.flickr.com/photos/scottchene/7046992749 https://commons.wikimedia.org/wiki/File:Timothy_Dalton_1987.jpg https://commons.wikimedia.org/wiki/File:Sir_Roger_Moore_crop.jpg
  45. 45. ©2017 Couchbase Inc. 52 There can be only one! https://en.wikipedia.org/wiki/File:Highlander_film_Connor_MacLeod.jpg
  46. 46. ©2017 Couchbase Inc. 53
  47. 47. ScalesWell Highly Available Data Agnostic
  48. 48. ©2017 Couchbase Inc. 55 Use Cases for K/V • Data variability • Object caching • Session storage • Large object storage
  49. 49. ©2017 Couchbase Inc. 56 Columnar
  50. 50. Keyspaces Column Families Rows Columns
  51. 51. ©2017 Couchbase Inc. 59 Keyspace
  52. 52. ©2017 Couchbase Inc. 60 Column Family
  53. 53. CREATE KEYSPACE mykeyspace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1'}; CREATE TABLE users (firstname text, lastname text, age int, email text, city text, PRIMARY KEY (lastname));
  54. 54. private static void DoStuffWithDataStax() { var cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build(); var session = cluster.Connect("mykeyspace"); session.Execute("insert into users (lastname, age, city, email, firstname) values ('Jones', 35, 'Austin', 'bob@example.com', 'Bob')"); var userBackOut = session.Execute("select * from users where lastname='Jones'").First(); Console.WriteLine($"{userBackOut["firstname"]} {userBackOut["age"]}"); }
  55. 55. Impedance Mismatch ScalesWell (Ops Headache) Suited to Analytics
  56. 56. ©2017 Couchbase Inc. 65
  57. 57. ©2017 Couchbase Inc. 66 Use cases for Columnar •Metering data •Really big data •Analytics
  58. 58. ©2017 Couchbase Inc. 67 Graph https://commons.wikimedia.org/wiki/File:The_protein_interaction_network_of_Treponema_pallidum.png
  59. 59. ©2017 Couchbase Inc. 68 Leonhard Euler
  60. 60. ©2017 Couchbase Inc. 69 7 Bridges of Königsberg
  61. 61. ©2017 Couchbase Inc. 72 Querying
  62. 62. ©2017 Couchbase Inc. 73 Use cases for Graph databases • Social networks / dating sites • Fraud detection • Parcel routing • Shopping recommendations
  63. 63. ©2017 Couchbase Inc. 74 Say what? Relational Document Key/Value Columnar Graph Object others…
  64. 64. ©2017 Couchbase Inc. 75 Box arrow box arrow Web Service SQL Riak S2 Couchbase Cluster Another Service Mobile Transactions
  65. 65. ©2017 Couchbase Inc. 76 Couchbase, everybody!
  66. 66. ©2017 Couchbase Inc. 77 Where do you find us? • blog.couchbase.com • @couchbasedev • @mgroves
  67. 67. ©2017 Couchbase Inc. 78 Frequently Asked Questions 1. How is Couchbase different than Mongo? 2. Is Couchbase the same thing as CouchDb? 3. How did you get to be both incredibly handsome and tremendously intelligent? 4. What is the Couchbase licensing situation? 5. Is Couchbase a Managed Cloud Service?
  68. 68. ©2017 Couchbase Inc. 79 CouchDB and Couchbase < Back memcached
  69. 69. ©2017 Couchbase Inc. 80 MongoDB vs Couchbase • Architecture • Memory first architecture • Master-master architecture • Auto-sharding < Back • Features • SQL (N1QL) • FullText Search • Mobile & Sync
  70. 70. ©2017 Couchbase Inc. 81 Licensing Couchbase Server Community • Open source (Apache 2) • Binary release is one release behind Enterprise • Free to use in dev/test/qa/prod • Forum support only Couchbase Server Enterprise • Mostly open source (Apache 2) • Some features not available on Community (XDCRTLS, MDS, Rack Zone, etc) • Free to use in dev/test/qa • Need commercial license for prod • Paid support provided < Back
  71. 71. ©2017 Couchbase Inc. 82 Managed Cloud Service (DBaaS)? Short answer: No. < Back Longer answer: Kinda. https://zdatainc.com/couchbase-managed-services/ Longest answer: See me after class.

×