Code-First Couchbase and .NET
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Alternative Title |
| |
Title of Series | ||
Number of Parts | 150 | |
Author | ||
License | CC Attribution - NonCommercial - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/51445 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
NDC Oslo 201395 / 150
3
4
5
6
8
11
12
15
17
22
26
27
31
32
39
40
41
42
44
47
51
53
56
57
59
60
61
63
64
66
67
68
69
71
72
79
80
81
82
83
85
87
89
90
93
94
95
97
98
99
100
101
102
103
106
108
109
110
114
118
119
120
122
125
126
130
132
133
134
135
136
137
138
139
140
141
142
145
00:00
CodeWeightTwitterObservational studyBlogContent management systemSubject indexingScripting languageJava appletFunction (mathematics)Server (computing)Hybrid computerView (database)Relational databaseAnalogyKey (cryptography)Hash functionSanitary sewerQuery languageSubject indexingCodeSpacetimeDatabaseWebsiteDevice driverGoodness of fitTerm (mathematics)QuicksortMassNumbering schemeData storage deviceNormal (geometry)CASE <Informatik>Endliche ModelltheorieFamilyRight angleConstraint (mathematics)Database transactionGame controllerMobile appSequelLocal ringFitness functionKey (cryptography)Forcing (mathematics)Touch typingTable (information)Business objectCartesian coordinate systemBoundary value problemComa BerenicesSlide ruleRelational databaseACIDView (database)Physical systemINTEGRALFigurate numberSpherical capBitSocial classMilitary baseInstance (computer science)Link (knot theory)MereologyHydraulic jumpLie groupData managementDifferent (Kate Ryan album)InternetworkingServer (computing)Row (database)CountingOperator (mathematics)Data dictionaryInsertion lossLibrary (computing)Client (computing)WeightProjective planeHybrid computerVisualization (computer graphics)Query languageAssembly languageObject (grammar)Mathematical optimizationSoftware developerMultiplicationSingle-precision floating-point formatDistribution (mathematics)Computer programmingVelocityPosition operatorLatent heatForm (programming)Cache (computing)TwitterMultitier architectureRange (statistics)JSONXMLUMLComputer animation
09:00
Partial derivativeGamma functionDew pointJust-in-Time-CompilerSystem administratorPhysical system2 (number)Revision controlClient (computing)WeightAssembly languageObject-oriented programmingPoint (geometry)Goodness of fitComputer animation
10:07
View (database)Physical systemCore dumpExtension (kinesiology)Focus (optics)Task (computing)Configuration spaceSpacetimeFluid staticsString (computer science)OvalDew pointGamma functionChi-squared distributionDefault (computer science)Client (computing)Message passingDialectNim-SpielLemma (mathematics)Convex hullKey (cryptography)Client (computing)SpacetimeCartesian coordinate systemDatabaseElectronic mailing listSheaf (mathematics)Mobile appClosed setConfiguration spaceInstance (computer science)Direct numerical simulationData storage deviceType theoryRow (database)ConsistencyTelephone number mappingInstallation artPhysical systemLevel (video gaming)Connected spaceMappingAuthorizationTerm (mathematics)Information securityParameter (computer programming)Social classServer (computing)Reading (process)Uniqueness quantificationDevice driverNumberDistribution (mathematics)Bootstrap aggregatingBitArithmetic meanTable (information)ExistenceEmailInsertion lossFunctional (mathematics)Asynchronous Transfer ModeEndliche ModelltheorieUniform resource locatorLibrary (computing)Hash functionSet (mathematics)Wrapper (data mining)Maxima and minimaCommunications protocolNetwork topologyPattern languageAbstractionDifferent (Kate Ryan album)Default (computer science)Multiplication signWeightCode2 (number)Thread (computing)PasswordNetwork socketTunisPerimeterInformationMessage passingPeer-to-peerPrice indexForcing (mathematics)Automatic differentiationRight angleState of matterSystem callOffice suiteCategory of beingObject (grammar)Process (computing)AnalogyQuicksortSequelDependent and independent variablesPoint (geometry)Computer animation
20:02
Client (computing)OvalFluid staticsDew pointWeightInstant MessagingView (database)MathematicsMotion blurPhysical systemSpacetimeGeneric programmingString (computer science)Category of beingTask (computing)Endliche ModelltheorieConvex hullSoftware testingPrice indexTwin primeDynamic random-access memoryAsynchronous Transfer ModeHill differential equationCorrelation and dependenceText editorAreaServer (computing)Sample (statistics)Default (computer science)Cluster samplingZugriffskontrolleRead-only memoryInformation managementoutputASCIIPasswordCommunications protocolTotal S.A.View (database)Task (computing)Endliche ModelltheorieSubject indexingForm (programming)Attribute grammarWaveVideo game consoleDifferential (mechanical device)Revision controlServer (computing)Cartesian coordinate systemValidity (statistics)Software developerReplication (computing)Sampling (statistics)Key (cryptography)PasswordInformationWeightOperator (mathematics)Computer fontBackupSocial classFlagMobile appApplication service providerProduct (business)System callInterface (computing)DatabaseGraph (mathematics)Multiplication signBitProcess (computing)QuicksortPoint (geometry)Client (computing)Game controllerCompact spaceAuthenticationData centerNumberData recoveryRepresentational state transferIP addressFront and back endsGraph (mathematics)Level (video gaming)Software frameworkAuthorizationBlogComputer fileGroup actionMathematicsCodeTemplate (C++)CASE <Informatik>Visualization (computer graphics)Sinc functionMereologyElectric generatorRight angleCAN busSelf-balancing binary search tree2 (number)Compass (drafting)Elasticity (physics)MiniDiscAd servingTouch typingSequelPhysical lawOffice suiteWeb 2.0Block (periodic table)Software bugPlanningSystem administratorLaptopRaw image formatSet (mathematics)MultiplicationDescriptive statisticsStress (mechanics)Tape driveElectronic mailing listCuboidComputer animation
29:57
DatabasePasswordCommunications protocolRead-only memoryText editorDew pointData modelView (database)Reading (process)LogicConvex hullPhysical systemFluid staticsHigh-bit-rate digital subscriber lineRAIDSoftware testingDreizehnControl flowSpacetimeGeneric programmingClient (computing)Set (mathematics)Task (computing)WindowMaxima and minimaBargaining problemLinear subspaceString (computer science)Chi-squared distributionSample (statistics)RotationError messageServer (computing)Configuration spaceString (computer science)Dot productDatabaseElectronic program guideIntrusion detection systemForm (programming)Field (computer science)Keyboard shortcutTask (computing)CuboidKey (cryptography)Data storage deviceCovering spaceIdentifiabilityCASE <Informatik>Interior (topology)ResultantSocial classObject (grammar)Instance (computer science)Configuration spaceCache (computing)Client (computing)RoutingPredictabilityOperator (mathematics)Exception handlingView (database)Query languageLibrary (computing)VarianceNetwork socketDatabase transactionQuicksortWritingCore dumpSerializabilityPattern languageFluid staticsBoolean algebraAsynchronous Transfer ModeCartesian coordinate systemType theoryMultiplication signInternetworkingMobile appComputer configurationSet (mathematics)SpacetimeInsertion lossCategory of beingMetropolitan area networkBit rateRight angleCasting (performing arts)Dependent and independent variablesSerial portDirection (geometry)Different (Kate Ryan album)Matching (graph theory)Term (mathematics)File formatElectronic mailing listParallel portTemplate (C++)Constructor (object-oriented programming)Line (geometry)Software testingProjective planeMessage passingCodeComputer animation
39:52
Dew pointMaxima and minimaError messageServer (computing)View (database)Execution unitGamma functionSign (mathematics)Client (computing)Fluid staticsStatisticsEndliche ModelltheoriePhysical systemWechselseitige InformationHilb, EmilSpacetimeTask (computing)Statistical hypothesis testingTerm (mathematics)EmulationReduction of orderDigital filterCodeSubsetOperator (mathematics)Key (cryptography)Query languageLevel (video gaming)Subject indexingBinary codeMappingUsabilityData storage deviceBasis <Mathematik>Category of beingCASE <Informatik>Electronic mailing listLink (knot theory)Software developerContext awarenessClient (computing)Transportation theory (mathematics)Row (database)Different (Kate Ryan album)Extension (kinesiology)VideoconferencingGene clusterForcing (mathematics)DatabasePoint (geometry)QuicksortTerm (mathematics)WordEndliche ModelltheorieTask (computing)Object (grammar)Range (statistics)Form (programming)CodePattern recognitionCycle (graph theory)Civil engineeringP-valueHydraulic jumpDefault (computer science)Server (computing)Scripting languageFunctional (mathematics)Function (mathematics)View (database)Social classProjective planeDecision theoryValidity (statistics)Medical imagingLoop (music)Set (mathematics)Reduction of orderProduct (business)Revision controlMultiplication signProcess (computing)Disk read-and-write headAnalogyCartesian coordinate systemFile formatSubsetDescriptive statistics2 (number)Touch typingSerial portBefehlsprozessorSelectivity (electronic)Mobile appProper mapFinitismusoutputMessage passingControl flowSystem callTemplate (C++)DeterminismTranscodierungNamespaceCountingText editorMeta elementComputer animation
49:47
Digital filterCodeView (database)Execution unitTask (computing)Dew pointPrice indexClient (computing)Wechselseitige InformationLine (geometry)SynchronizationError messageServer (computing)String (computer science)SpacetimeEndliche ModelltheorieWalsh functionSubsetData modelElectronic visual displayTask (computing)Query languageInstance (computer science)Client (computing)Subject indexingParameter (computer programming)CollisionView (database)Functional (mathematics)Pattern languageRow (database)Key (cryptography)QuicksortCategory of beingDifferent (Kate Ryan album)Product (business)Level (video gaming)String (computer science)Numerical taxonomyMultiplication signMereologyElectronic mailing listType theoryOrder (biology)AdditionMathematicsResultantTunisFlagSet (mathematics)Semiconductor memoryDatabaseRange (statistics)Demo (music)MiniDiscRight angleReading (process)Inheritance (object-oriented programming)CountingProjective planeSummierbarkeitStandard deviationNetwork topologyAnalogy2 (number)DreizehnLie groupPoint (geometry)Computer fileScripting languageJava appletOffice suiteSystem callEvent horizonTouch typingTape driveDataflowUltraviolet photoelectron spectroscopySequelWater vaporComputer animation
59:42
Price indexDemo (music)CodeStatisticsView (database)String (computer science)Point (geometry)InformationMiniDiscSpacetimeGeneric programmingPhysical systemDew pointMIDITime domainAbstractionRepository (publishing)Glass floatClient (computing)EmailWechselseitige InformationInstant MessagingContent (media)Twin primeHexagonWeightBit rateDiscrete element methodPlot (narrative)Information managementSoftware testingDatabaseCategory of beingSubject indexingFrequencyView (database)Pattern languageSocial classPhysical systemError messageDatabase transactionFormal verificationSoftware frameworkObject (grammar)Connected spaceType theoryExistenceQuicksortSpacetimeCartesian coordinate systemSemiconductor memorySampling (statistics)Multiplication signDot productComa BerenicesInterface (computing)Replication (computing)CASE <Informatik>Limit (category theory)SequelData warehouseAffine spaceInstance (computer science)Server (computing)Client (computing)Repository (publishing)40 (number)Mobile app2 (number)Web pageSoftware developerScaling (geometry)Computer hardwareComputer-assisted translationElectronic mailing listForm (programming)Query languageAttribute grammarParameter (computer programming)InformationTouch typingKey (cryptography)Link (knot theory)Complete metric spaceINTEGRALEndliche ModelltheorieCodeData centerLotus NotesStandard deviationDefault (computer science)ThumbnailConfiguration spaceRule of inferenceOperator (mathematics)Computer animation
01:09:37
Software developerComputer animationJSONXMLUML
Transcript: English(auto-generated)
00:06
All right, I think we're about to get started. Thanks everyone for coming out. Just a quick check in the audience to see where people are with NoSQL and Couchbase and that sort of genre. How many people have heard of NoSQL before?
00:21
This is good. A couple years ago there were very few hands, so obviously it's becoming a little more pervasive. How many people have heard of Couchbase? That's pretty good. CouchDB? MongoDB? So that's sort of the broad range of NoSQL technologies
00:40
that you've probably encountered. Cassandra might be another one you've encountered. So what I'll do in the beginning of this talk, the talk is really about .NET and Couchbase and writing apps with the .NET client library that I previously supported. And what I'm going to start out with, though, for those of you who are new to Couchbase is just a quick, quick overview of Couchbase
01:02
so you can see how it kind of fits in with all those other NoSQL systems. So a little bit about me. I've recently changed positions. I used to work for Couchbase. I was the developer advocate doing the .NET SDK. I decided to kind of take a different path a couple weeks ago, so I actually worked for a company that's headquartered out here
01:21
in Europe, Education First. If any of you have been lucky enough to spend a year abroad during high school, you might have gone through our program. I have run the Boston Code Camp. I'm from Boston, Mass, so I run the Code Camp out there. Do you guys have Code Camps out here? So the all-day Saturday dev events, local community stuff.
01:41
And if you have any questions for me, you can find me on Twitter at code voyeur, or you can just find me at johnsablocki.com, and there's a link to a form where you can contact me. If you have any questions about anything with either Couchbase or NoSQL after this talk, definitely feel free to drop me a note. So like I said, I'm just going to take about five minutes
02:02
to cover what Couchbase is and how Couchbase differs from some of the other databases that you may or may not have heard of. But my first question for the audience is, how many people have used a dictionary? Not the physical book, the actual. How many people have used LINC?
02:21
So fundamentally, it looks like everyone in this room has the background knowledge for working with a database like Couchbase. The concepts from LINC are going to key in heavily to the way we do indexing with MapReduce, and the concepts from dictionaries are going to obviously play into the key value store aspect of Couchbase. So Couchbase is a hybrid.
02:41
So a lot of NoSQL databases tend to fit into one bucket only. And that bucket might be a key value store, or it might be a document store, or a multi-column, or some specific genre. But Couchbase is a hybrid database as of 2.0, which came out last December.
03:00
So Couchbase is both a key value store and a document store. And it's a key value store in that the CRUD operations, the primary CRUD operations, are all done through simple key value API. Has anyone worked with Memcached? What's App Fabric? Is that what it's called now? It used to be Velocity, Microsoft's App Fabric,
03:21
the distributed caching tier on Azure. So basically, Memcached was the original distributed cache across multiple nodes in a cluster of Memcached servers. And Couchbase is fully compatible with Memcached. So if you've used Memcached, you understand the primary API for working with Couchbase. But again, if you've worked with the dictionary,
03:41
you also understand how to work with key value pairs. So it's a very simple API for putting data in and getting data out. It's a little more interesting when you want to create a secondary index. And that's what we're going to talk about later on, basically. So you've put everything in by key value, but now you want to find users by last name, and their key is not their last name.
04:04
So a couple other concepts. So again, everything is done with the key value API. You store documents in a bucket. So if I use the term bucket, think of it as a database. It's not precisely a database, but you can kind of think anywhere in SQL Server where you would have right clicked new database,
04:21
you would create a new bucket in Couchbase. And then again, secondary indexes are going to be created using JavaScript, and I'll show you a couple examples of that. So rather than, I'm going to try to minimize how many slides I look at. I want to just actually dig right in. I did call this talk code first, so I want to jump right into some actual simple code.
04:44
So before I jump into the complete example, I think it's useful to start with the hello world, so you can understand what is this Couchbase thing, if you haven't seen it. How many people have actually seen Couchbase? I know a bunch of you have heard of it, but has anyone actually used the product at all?
05:00
So a lot fewer people. So I'll jump in with a simple hello world, and then we'll kind of work our way up into a more interesting example. How many people have heard the term code first before? So code first, for those of you who haven't heard, generally refers to the idea that before you design your schema, you design your business objects. And the business objects become your database schema.
05:23
Now in Ruby on Rails, it's the active record model where you basically define some active records and then auto-generate the schema. Well, I think with NoSQL, it's an interesting approach, because everything is code first. You don't define objects. You don't define a schema. So Couchbase is a schema-less database, as we'll see as we go along.
05:42
There's no definition of a table. There's no definition of something that has a schema. So you define your objects, and that's how they get saved. Does anyone feel like that's scary, not having a schema? People don't want to admit it. So I'd ask you to consider things like, OK, so one
06:02
of the things that really bothers people at first, instinctively, is there's no schema in this database. How do I control what goes in there? But let me ask a couple questions. How many people have gotten their schema right on the first try before? Usually at least one person says they have.
06:21
How many people have denormalized their database to make it perform better? So one thing I like to say about NoSQL, a lot of people look at NoSQL and think it's creating a new class of problems. I like to think that it's creating a new class of solutions. So we don't have new problems. We just have the same problems with different solutions.
06:41
So you've denormalized that database, because that query that joined to 10 tables that were perfectly normalized took 10 minutes to retrieve one row. So NoSQL databases tend to start from the other side. Let's optimize first, not worry about having a table with 10 million rows and a column that's null in 900,000 of them. So let's not artificially impose a schema on our data
07:04
when it doesn't really have one. Or let's not artificially enforce these constraints that really don't perform well. So NoSQL takes the other approach. We need to perform first, and then we'll figure out how to deal with referential integrity and that sort of stuff. And it gets bubbled up to the application in general.
07:22
This is the other scary part. There's no referential integrity or transactions beyond a single document insert in a NoSQL database. And there are a couple of fringe databases. And fringe isn't to discount them, but they haven't really caught on that are actually ACID compliant, and that would be NoSQL databases. But generally speaking, the major players
07:40
do not support ACID properties. So you don't get cross-insert, cross-update transactions. But a lot of this stuff goes away. When you think about some of the common use cases, the way you store your data in a relational database is I insert into five tables because they're normalized versus one document that contains all my data.
08:02
So that sort of need to have a transaction boundary across a lot of tables goes away because you don't have a lot of tables. So again, a lot of these problems are not new problems. They're just solved in a different way. So now with that said, I'm going to go back to my Hello World example here so we can get a quick view of how I create an instance of the Couchbase
08:23
client, how I configure it, how I insert a key, and how I read the key. So the most basic operations. So I haven't actually, I think I have internet access that's working right now. This doesn't always work, depending on the venue.
08:40
So I'm going to look for the Couchbase net client. Does everyone use NuGet? Does anyone not use NuGet in the room? So if you haven't used NuGet, it's a package manager for downloading assemblies in Visual Studio into your project. So basically a reference manager. Oh, yes, that would let me, I don't need my slides anymore.
09:00
Sorry. Can everyone see that OK now? So I'm going to search for the Couchbase net client, which is the official SDK. And I'm in my installed packages.
09:21
Let me go to online here. There is a second Couchbase net client that is an older version. I don't know why NuGet is keeping that up there twice. I've removed this one as far as I know. But 1.26 is the most recent version.
09:43
And it supports .net 3.5 and 4.0. So now that I've added that reference, what I get is a reference to three different assemblies. The only dependency that the Couchbase net client has is JSON.net, which pretty much everything has a dependency on.
10:01
Previous versions had a dependency on rest-sharp and hammock, and those are no longer there. Oops. That wasn't right. So you can see this. That's my magnifier in the way, of course. Enum.caching. If you've used memcached with .net, you've used enum.caching. This is basically where most of the functionality
10:22
exists inside of the Couchbase driver. And that is a fork of the original enum.caching. So if you encounter anything out in the wild, that's enum with Couchbase, there's a particular fork that ships with the Couchbase client, not the actual enum.caching.
10:42
And then the CouchbaseAssembly is the other one that has all of the Couchbase-specific wrappers around the enum stuff. So now, once you have those references, you can either configure the client in code or configure it in AppConfig.
11:00
I prefer code. I think more and more I've seen as I've gone out into the wild, people do prefer code configuration. So there's a class called the Couchbase client configuration. And the minimum configuration you need is a bootstrap URL.
11:24
And I'll explain this in just a second. So when the Couchbase client initializes, what it does, and this is unlike other NoSQL and SQL databases.
11:40
So what it does is the Couchbase client starts up. It spins a thread that goes and listens to a streaming HTTP connection. So basically, the Couchbase cluster, which is just a bunch of Couchbase nodes that are acting as peers, it connects to one of those nodes, which sends down topology updates. So the actual client that's running in your application
12:00
space knows about the topology of the cluster. So cryptographically, it hashes each key that you set for a value, and it sends it to a particular server. So as you add nodes and remove nodes, the client knows how to go directly to the right server. So it maintains a map of, there's actually a layer of abstraction between the client and those keys and how they're mapped.
12:20
So that's much more finite, because you wouldn't want to have a map with millions and millions of keys potentially on the client. But the client always knows how to go right to the right server that owns the key. So in a Couchbase cluster, the nodes are all peers, except one of the nodes owns the key as a master. So the key can be replicated up to three times on other nodes,
12:40
but it's only on one node as a primary key. Not primary key in the SQL sense, but it lives as a master instance of that key. And that way, Couchbase is consistent. There's different types of consistency levels for NoSQL databases. Some databases are called eventually consistent.
13:01
Has anyone heard that term before? So eventually consistent, kind of the common example is the DNS system. You can update your DNS record, but that DNS record has to propagate to the other nodes in the DNS system before all requests see the most recent update. Couchbase is consistent, because when you say get by this key, only one server in the cluster
13:23
can answer that question, versus other databases where Cassandra's eventually consistent, it's tunable. You can force consistency a little bit more. But basically, what happens is when you request from an eventually consistent database, you could get a dirty read. You cannot get a dirty read with Couchbase.
13:44
Technically, you can, but the .NET SDK doesn't expose the replica reads, which is how you would do that. Sure. So the question was about the failover scenario.
14:02
And what happens is, assuming that you've replicated your nodes, or replicated to another node, at least two nodes, there's an election of one of those servers to become the new master for that key. And then the server rebalances the keys. So another thing I'll mention about the keys is they're auto-sharded. Is anyone not familiar with the term sharding?
14:23
So sharding meaning distributing keys across a number of nodes in your system. So you can shard a SQL table so that you basically spread the rows across many nodes in a cluster. So sharding in like MongoDB, for example, was kind of controversial because famously, Foursquare
14:41
picked the wrong shard key, kind of overloaded some set of their shards, and that brought Foursquare down. This is many years ago. This isn't like a recent thing, but it kind of was a classic example of why sharding is hard because you can't predict that first names are going to distribute, or last names are going to distribute evenly across your data, versus a cryptographically hashed key
15:01
in your key value pair. It's pretty safe that you're going to get, if you have a three node cluster and 100 keys, you're going to have about 33 on each node. So you can almost guarantee that with Couchbase, if you have n number of nodes, you're going to have even distribution across the n nodes
15:21
for your keys. And you don't have to do any kind of predicting because it's all done automatically. OK, so that's the bootstrap URL. So there's basically like a JSON handshake that happens when the client starts up, it gets a JSON response, it reads it, gets a next URL to go to get a little more information,
15:41
and then it kind of goes through that once or twice. Because of that, you don't want to create multiple instances of your Couchbase client. It's not the typical database pattern where it's using connection equals new connection and starting over. You're going to end up kind of re-handshaking every time. So that does mean that you have
16:01
to have a stateful client. Generally speaking, you keep a static member somewhere that you reuse throughout your application. There's also a socket pool. You can fine tune how many connections are in the socket pool. So basically, it'll maintain, by default, a set of 10 connections to each node in your cluster.
16:22
The other thing you need to tell Couchbase is which bucket to connect to. So again, buckets are databases. They're analogous to databases. So there's a default bucket that's installed when you run through the wizard and install Couchbase. So it's just an auth list.
16:42
So the auth model in Couchbase is sassle. So it's just basically, if you've used, it's a simple binary protocol. It's not encrypting anything. It's not user-defined object-level security. It's just, I have a bucket. I can either put a password on it or I don't. The username is the name of the bucket. You can set a password on the bucket.
17:02
And again, that's not unique to Couchbase. Most NoSQL databases don't have granular security. You may have object-level database-level users. And you may have read-only versus write-accessible. But generally speaking, NoSQL databases do not have the same security model yet as SQL databases.
17:25
So now that I have my configuration, I can create a new client. So it's the class is Couchbase client. And if you use the parameter list constructor, the client will expect that you have an app config section defined for Couchbase.
17:42
Or I can just pass my config instance. So now, we'll ignore return values for now and assume everything's going to work because this is the Hello World example. So I'm going to create a message.
18:03
Did I get that right? Was that right? Close enough. And so then I'm going to save that message. So the store method is the basic method for doing ads, updates, and replaces.
18:22
There are three types of stores in Couchbase. You can add, which does an insert. It'll fail if the key exists. Replace doesn't update. It'll fail if the key doesn't exist. Or a set, which is basically like a save, which
18:40
does an insert if it doesn't exist or an update if it does exist. So add is useful. Generally speaking, I usually use just the set mode. But generally, if you have things that you want to fail, like creating a user based on their email address, and you want the user property, whatever, to be unique, add is a way of guaranteeing that.
19:02
And you get a status back that says the key exists or something to that effect. So you can check to make sure that you are ensuring uniqueness and getting the proper behavior. So I'm going to set the store mode to set, the key to message, and the value to message.
19:21
So it's slightly more complicated than a hash table because I have to set the store mode. The other SDKs, the Java, Ruby, and everything else, they don't have this idea of a store mode. They have straight methods that are set, replace, and add. This is an artifact of the nyim.caching library. I personally would, at some point, would like to see three unique methods there.
19:42
So then we'll make sure that it worked by getting the value back. So the key is message. So when I set it, I set it with a key. When I get it, I get it with a key.
20:01
And if all worked, I should get my almost Norwegian hello world. So any questions on the very basics of hallo werden? I'm trying. I feel like because I'm reasonably tall and mostly
20:22
blonde, I've been mistaken for Norwegian quite a bit since I've been here. OK. So now I want to move on to a more interesting example, which will kind of walk through a full CRUD application, some of the more advanced usages, and basically just
20:42
show how you do code verse development with a NoSQL database. So I think everyone's familiar with the idea of a task app. You have a task. It has a due date, that sort of thing. So I'm going to start out by creating my model. And this is the code first aspect. If you haven't done, quote unquote, code first development with entity framework or something,
21:01
the basic idea is you define a model class. So I'm going to define a model called task. Can you guys, is the font size big enough? And my task will have an ID, a description.
21:28
We'll say notes. We'll give it a is complete flag and a due date.
21:47
So very basic model. Any questions seems pretty straightforward. So now let's go ahead and how many people have used, not used MVC before?
22:03
Excellent. It is interesting. Over the past couple years, I'd say it's increasing by about 25% a year, the number of people who have gotten exposed to MVC, which is a good thing. So I'm going to create a new controller. I'm going to use the wizards as I go through this demo,
22:21
just so it speeds things up. So I'm going to create an MVC controller with empty read-write actions. And I'm going to call the controller tasks controller. So all I'm doing is creating a very basic CRUD application for managing tasks at this point. So the index is actually going to be the hardest piece
22:43
that we do. So I'm going to do that last. It's hardest because we haven't seen how to work with secondary indexes yet. So I'm going to start with the create form. And I'm not going to worry about things like validation or that sort of stuff. We're just going to keep this very simple.
23:00
So I'm going to use the, has everyone used the scaffolding in Visual Studio for MVC? That's all the stuff that I'm doing now as part of the scaffolding feature of MVC, where you can basically point it out a model and generate forms and things like that in controllers. So I'm going to create a new view under the tasks folder.
23:25
And we're going to start with create. And then it's a strongly typed view. And this drives me because you have
23:41
to compile your application before it actually shows up in that list. So I'm going to call this view, create again, strongly typed. So now my task shows up. So now this is going to give me a nice create. If I pick the checkbox that says to use the create.
24:08
So I forgot to set the template to create. So what this did for me at this point, in case you haven't seen this before, if I navigate now
24:21
to task slash create, I have a very simple create form. There's no validation because I haven't put validation attributes on or anything. But it's just a very basic create form that I can work with from now on. Before I do that, what I want to do
24:41
is jump over to the couch base. If I wave at my laptop, it detects that and starts to do things. So it may move on its own. I did cheat for the hello world. So this is the Couchbase console.
25:01
So it seemed like only a couple people had seen this. One of the big differentiators between the other NoSQL products and Couchbase is Couchbase has, in my not so unbiased opinion, the best admin tools. This is what you get when you install Couchbase. It's a web-based, fully exposed API.
25:21
This is a jQuery app. This isn't like a server doing complicated stuff on the back end. This is a full RESTful API, an interface to a fully RESTful API. So if you're ever curious to see what is actually happening, you can just use Firebug or whatever tool to go look at the calls that are
25:40
being made to generate these graphs and things like that. So when you install it, you get some basic information. So I have a couple of buckets active. You can see ops per second. If I actually had ongoing ops per second, I would get to see the moving graph. You can see if you had any servers down in your cluster.
26:02
You can drill into the node level. So if I had multiple nodes, so if I want to create a Couchbase, a true cluster, a cluster is just a single node or more nodes. If I wanted to have a multi-node cluster, I click on Add Server. I add the IP address. And then I add the cluster username and password. So when you install the first node, you set a cluster account.
26:22
And that cluster auth is used to then basically bring all the other nodes online in the cluster. And if I had in that failover case, it would show up as pending rebalance, because basically the keys need to be rebalanced data buckets.
26:43
So the beer sample bucket, the beer sample is based on the OpenBeerDB. This is the Couchbase version of Northwind. So it's not the most up-to-date database. So if you're a beer drinker, you probably won't find the beer you're looking for in there.
27:00
But there's some interesting data. And we wrote a bunch of sample apps around it, which if there's time at the end, I'll show you quickly the .NET one. Views I'm going to cover in a bit. Cross data center replication, this is a nice feature. You can actually pump data bi-directionally out of Couchbase. And bi-directional cross data center replication is set up by basically setting up two unidirectional cross data center replication.
27:22
I don't know what the coasts are here, but like in America, if you have an East Coast and West Coast data center, you can send data one way and have it sent the other way. Or you can just use unidirectional and have a single feed into another data center for backup or disaster recovery. The neat thing about it is it's all done with HTTP.
27:43
So if you wanted to write your own HTTP endpoint for the Couchbase data across data center replication, you could. And we've done that to work with Elasticsearch. So if you want to pump data into an Elasticsearch cluster and do full text search on your documents, you can do that. Has anyone used Nancy, the micro framework for ASP.NET?
28:04
So it's kind of inspired by Ruby's Sinatra. So it's a very simple handler. I wrote on blog.couchbase.com, you can find a little example where I created a Nancy endpoint which listens to the change feed and then just spits out data into an XML file as a dummy example.
28:22
But if you wanted to move data from Couchbase into SQL Server, that's one way to do it, or into some other back end processing. The log is what it sounds like. Then you can set some settings, like re-adding some sample buckets, whether you want to have compaction and basically cleaning up the disk, auto failover,
28:44
and that sort of thing. What I want to do now is add a data bucket. So for this to-do application, I'm going to create a new bucket, so this is a new database. And when I create this, I'll just give it the name, NDC Oslo.
29:02
Now again, we're fully compatible with memcache-d, so if you wanted to create a memcache-d bucket, you can, but there's no persistence. So if you wanted to use Couchbase, and we do have lots of clients who use Couchbase as a caching layer, because we have that memcache-d support. So you can actually just drop out your memcache-d cluster and replace it with a Couchbase cluster
29:21
and use memcache-d buckets. But again, there's no persistence with those. And the performance really isn't going to be better, so you could just create Couchbase buckets and set expirations on. There is the ability to add an expiration to a key, so you can have it expire and that sort of thing. You can change the port. I'm sorry, you can't change the port
29:43
with a standard authenticated. If you create an authenticated bucket, it has to be on port 11211. If you want to have an authless bucket, you can do that just on a different port. So I'm going to leave the password blank for now. I only have a single-node cluster, so there's no reason to enable replicas.
30:05
Flush is useful if you want to have a test bucket. So basically, you want to just flush all the data out of the bucket. When you enable flush, you basically have a one-click, I can now delete all the data. Option. So I have that bucket now.
30:21
You can see it in my bucket list. Are there any questions on the UI before I start with a code? So now the first thing I want to do is implement the create method. So I don't need to do anything on the create get,
30:41
but for the create post, I need to write the insert method, basically. So what I'm going to do is start off by creating a static private field of type couch-based client.
31:03
And I had previously added the couch-based client reference through NuGet to this project, because I wasn't sure about the internet access. So that's where that came from, in case you're wondering. And what I'm going to do is, in a static constructor, so static constructors, if you're not familiar with them,
31:21
are guaranteed to execute once before any instance of the class is created. So in the static constructor, I'm going to create an instance of this couch-based client.
31:43
I also need to set that configuration like I did before. So var config equals new couch-based client configuration. Again, set the URI so it knows where to bootstrap against.
32:09
And then the bucket name. What do I call it? NDC Oslo. And then I pass that config to the client.
32:22
So now I have a static field that I can now use across all my methods here. And that was, again, just what we saw with the Hello World stuff. So now in Create, what I'm going to do is, let's see.
32:40
I'm going to change this. Instead of taking a forms collection, I'm just going to have it auto bind to the task using the kind of bidirectional data binding that comes with MVC out of the box. So now that I have a task, we're a key value store.
33:04
So I need to consider what the key is going to be. Now, a lot of times, predictable keys are useful because you can do ordering on keys and things like that with views that we'll see in just a few minutes. But the important thing is that you pick a key that makes sense for your scenario. Now, there's really not value in having a key. There's no auto key, first of all.
33:22
I do an insert, and I don't have a key, so it automatically assigns one. You have to pick a key. And so generally speaking, if I were doing a to-do app like the one I'm demoing now, I would just use a GUID or some unique identifier. There's not really any value in having a descriptive key for a task.
33:42
If someone has a better reason to do that, I'm open to that. But I think the best way to do this is just GUID dot new GUID dot toString. All keys in Catchbase are strings, UTF-8 strings.
34:02
Oops, not result, key. So now, I'm going to call the store method, but I'm going to call a different store method. So one of the interesting legacy items I had to deal with when I first took over the Catchbase client was that it was a caching library under the covers.
34:21
So the core of the library was a caching library. And in a caching library, arguably you don't want exceptions thrown if something is a cache miss or something is a cache fail, cache write fail. You either got it out of cache or you didn't, and your application responds appropriately.
34:40
So what was happening in the internals of the client is every single exception was being swallowed and Booleans were being bubbled up to the top. So if you called store and it failed, you got a false. Now, if you're storing a transactional financial data or something, you probably don't want false as the reason why something failed. So there's this sort of parallel API.
35:01
So every store, get, remove method has an associated execute dot dot dot method. So execute store returns more detail than store. So store returns a Boolean, execute store returns an operation result, which I'll show you in just a second what that contains.
35:21
So we'll do store mode. We're doing a create, so I'm going to do store mode dot add. The key, again, is that GUID. And the thing we're going to save is the task. So then that result object. So you can do things like check the success of the result. So a common pattern.
35:41
If it's successful, or if it's not successful, I should say, you can check things like the message, the status code, or the exception. So if there was an exception way down in the socket layer, it basically gets wrapped up and passed up through this exception object. So there's no exception that's thrown, but you can check to see if exception is not null,
36:03
then throw that exception. So I won't go through that exercise of all that detail, but just so you know, there is a bunch of detail about what went wrong or what didn't go wrong inside of that result. So let me claim some space back here.
36:22
So now on the next line, I'm just going to redirect to the details. So we'll kind of work our way. We'll create it, and we'll show the results in the details. So redirect to action, details.
36:40
So I want to redirect with the ID set to the value of the key. Return. Return. So there are a couple of issues I have to fix that I just know from doing this a bunch of times. You have to save serializable objects through the client.
37:02
So if you're saving a class, it has to be serializable because it gets serialized and saved. And the other thing is because we're dealing with string IDs, with an MVC template, you get int IDs. So you just have to change. So on edit and on details, these int IDs
37:20
have to be string IDs where the routes don't match. And since we're going to details, let me just find that.
37:43
So now, let me compile that. So now, this should still be good. So I'm going to just create a very simple task here.
38:06
And there's my gesture thing popping up because it is not complete. We'll give it a due date of 6-14-2013. Apologies. OK, so this I expected, right? So I haven't created the details format.
38:23
So no exception was thrown. Here's my GUID. Well, I'm going to go through details first, and then I'll show you what's actually in the database. Are there any questions on create so far? Pretty straightforward. I have a key. I have an object that's serializable.
38:41
I save it. There's not much more to it than that. Now in the details, I'm just going to get by key. So the key was passed here in the query string. So I have the key available to me.
39:01
And that's coming in through the route as this string ID. So var result equals client.executeGet. And I can use the generic executeGet, which will automatically cast it to a task on the way out.
39:21
And then the key is the ID. And then I just pass that. So the executeGet method returns an I get operation result, which has a value property, which is the thing I saved. It also has the exception property, the success property, and all those things. So that just wraps all that stuff.
39:41
The get method returns either null or the object with no detail about what went wrong. So now I'm going to create the details view. I'm going to name it details. Scaffolding template of details.
40:04
So now if I compile and refresh this YSOD, then I should get. So now I have the description showing up. So pretty straightforward getting set. It's really just what we've seen so far in our console
40:21
app. But what I want to show you now is what's actually in the database. So you can see in NDC Oslo, we have one up per second. So we're doing pretty well there. If I click on documents, one you can see over here that I have an item count of one.
40:43
And if I click in here, you can see here's that document. Here's the key. So this is a little strange, though. I've said before, Couchbase is a document oriented database. That doesn't really look like a document. Anyone have an idea of what that is?
41:03
Base64 encoded version of the binary object. Now I didn't store JSON. Here's a big difference between Couchbase and MongoDB. MongoDB forces everything into BSON, binary JSON. Couchbase does not.
41:21
Couchbase stores binary objects. It stores JSON as just a special recognition object you can think of it as. So on the server, if you store valid JSON, the server can do stuff to that JSON document. The client has to make a decision as to whether it's going to pass JSON or not.
41:41
And to make that easier, what you can do is use some extension methods. So we've thought a lot about whether we should force people to store JSON. We have a legacy of a lot of binary data being stored. So we couldn't just release 2.0 and say, oh, all that data that you stored binary, now it has to be JSON.
42:01
So we have plus some people don't want to store JSON. They want to store just objects in their binary form and retrieve them quickly. People are storing images. People are storing all sorts of different things in Couchbase clusters. So there are lots of use cases for not storing binary objects. JSON's very expensive. We heard from a former CTO of Zynga that they were spending 30% of their CPU cycles
42:23
just doing JSON serialization and deserialization. That's not insignificant, obviously. So I do have some extension methods, though. If you want to always, under Couchbase.extensions, you can basically take any of the execute methods
42:41
and tack the word JSON to the end of it. So if I say execute get JSON or execute store JSON, if I compile that and go back to my form,
43:02
we can see something else that happened. Just create a task two. So everything worked as it did before. But now if I go back to my documents, you'll see that I have JSON stored here.
43:23
So I have a useful thing, as far as the server's concerned. I have a JSON document against which I can write a secondary index. So I'm just going to store a couple of these tasks quickly and just change some dates here.
43:42
And we'll create a task four. We'll call this. OK. So now over here, I've just basically created some more data to demonstrate the list, which is the next thing we'll do. Before I jump into the list, which is going to switch to secondary indexing,
44:02
does anyone have any questions? It's still non-JSON in there. Yeah, that'll break because if I took this,
44:27
I apologize that I didn't bring music. So if I try to drop this in, I'll get a deserialization problem.
44:40
Well, the model doesn't have an ID, so the form is actually breaking. But it won't deserialize because it's not a string. Backwards compatibility. And there are a bunch of challenges with backwards compatibility because you
45:00
can store a document that doesn't deserialize properly into your class. You can have binary data that's not going to store properly. There are solutions for all that stuff, whether it's versioning your documents or just having. You can create something called a custom transcoder. So the transcoder is basically, it's pluggable. So you can basically tell Couchbase every time you deserialize something,
45:21
if it's of some particular format, then deserialize it into binary and then JSON. So you can look up transcoders and see some videos that we had done on how to do some of that sort of special mapping. So my question would be then, so everyone knows how to work with key value stores, how would you get a list of all the tasks
45:43
with a key value store? Can anyone imagine how you might have done this? If all you had was this key value API, how would you go find all the keys? Kind of a trick question.
46:03
And I'll show you how to do it without. This is not using the key value API to do that. So with Couchbase 1.8, which was a pure key value store, the sort of approach that people took was to store keys in another key. So if you wanted to say, when I create a task,
46:21
also insert the key into the tasks list. So you're basically storing references in other keys, pulling them all back. There were some other, like if you had sequential keys, you could do basically a bunch of gets until one failed by incrementing up one. And then you kind of knew the one that failed, that's the top one, and now grab them all. None of it's pretty.
46:40
Everyone kind of realizes that. So secondary indexing really is much prettier. It's much nicer. So let me jump right into that. So the way secondary indexing is done, it's something called a view. Has anyone heard the term MapReduce before? So MapReduce, if you've used a link,
47:02
you've probably had some sort of MapReduce exposure. Think of a very basic idea. You have some collection of things. In this case, all the documents. You have a map function. The map function is going to be applied over a big for each loop, over each of your documents. And the input to the map function is the current document.
47:21
The output is a key value pair. The key is something you want to search on or something you want to create an index on. So it's basically just transforming a set of data into a projection, which is a key value pair. And you can do that with a .where, .select in link. So if you want to think of a link analogy,
47:40
the map function is kind of like the .where and the application of the .select to shape it into a key value pair. Let me show you in JavaScript what that means, though. So we have this idea of development versus production views. So development views are done with basically taking
48:01
a small set of your production data. So let's say you want to create an index on a million records. You don't want to start with all one million records. You want to start with a finite subset of that. So development views are deterministic. They create a small subset. They basically grab a small set of your data and mark it as usable in a development view. It's a useful way not to break things.
48:24
Design documents are namespaces for your index definitions. So I'm creating a design document called tasks, in this case. The dev underscore is what makes it that deterministic dev database. I'm sorry, design document. And the view is just going to be all.
48:43
So I want to get all tasks. So once I create that, I click in and I have this editor where I have a map function, which is just a JavaScript function that, by default, creates an index on the ID.
49:01
Now, the only reason you would ever create an index on the ID is so the ID is the key. So one of the confusing things to get your head around is in the context of key value CRUD operations, the key is the key in the key value operation. In the context of a view, the key
49:21
is the meta dot ID, because views actually create a new key value pair, which is the index. So when I'm talking about keys in terms of views, I'm talking about the thing I'm indexing. So I'm creating an index on a property. That property is called a key.
49:40
So if I run this, you see I just get all documents along with the index created on their ID. Now, this is the primary key. So this is just like creating a secondary index on a primary index. You wouldn't do that, obviously, unless you want to do a range query on your primary key. You can't do range queries on keys
50:00
without creating an index on them. You can't say, give me all the keys that start with A and go to Z if you don't have an index on that, secondary index. But what I want is really just null. So I want all tasks. So I don't care about the key. I want to create an index that will just return all of the data for a set of tasks.
50:24
So let me show you how this actually works by showing you the JSON that comes back to the SDK. When you create an index, you create a triplet of rows. You create a set of rows where each row is a triplet. And the triplet consists of the original ID,
50:40
so the key from the key value insert, the key, so the thing you're indexing. So if I had a first name or last name, that would show up in the key. And the value is potentially a projection over which I'm going to do aggregation, which I probably don't have time to get into today. But if I were doing a count of tags, I would project something into that, or sum of tags. I may, or sum of karma points,
51:01
I may project that into a value and then do aggregation on it. But the important thing is that with every row in an index, and this is just a standard B plus tree database index, with every row, I have the ID of the original document. So what I do with that ID, generally, is go back to the original document in memory
51:21
and pull it out. Because Catchbase has persistence. So views are basically indexes that are stored on disk, right off of disk. But you go back to the memcached API, because your document is 99% likely to be in memory. So all of those documents are resident in memory if you have enough memory.
51:41
So any most recently used document will be there. So it's kind of a different access pattern than your typical database, where you wouldn't generally create an index to get the primary key to go back to the original row. But that's what you do in Catchbase, because you create an index to get the ID to go back to memory. So it's just a different sort of workflow.
52:03
But that's abstracted from you and the client, and I'll show you that now. So let me do the all query here, and then I'm going to change it to something that will hopefully illustrate what that key and the key value is a little more easily.
52:20
So now if I go back to the client, that's going to be an issue I'll show you in just a second. That was a good catch. So the index method, what I want to do
52:47
is call the client's get view method. There's a generic get view, which will convert your documents into an instance of T.
53:01
So my design document was named tasks, and my view name was all. And there's a third argument that says go pull it out of memory, instead of trying to deserialize that value. And then I'm going to pass that view to the index file, to the index view.
53:23
Again, we have a name collision with view and view here. So I'm going to create a MVC view called index with a list scaffolding. So one more quick thing I have to do over here is I have to promote this from dev to production.
53:44
So when I publish, now you can see I have a production view. So basically I just took the dev underscore off the name, so that it'll go against my entire data set. So now if I go back to list, so this
54:06
is part of the problem that a couple people have mentioned. So I have this binary thing sitting in there. I can't convert that. My view just emitted everything, and there's
54:21
no way for me to know that a document is a task. We don't have a concept of a collection or some kind of container for documents in Couchface. There's a bucket, and the bucket just contains documents. So the convention is to include a type on your documents.
54:43
So what I usually do is define a base class that forces you to implement an abstract type. So we'll just return task. So this demonstrates the schemaless idea. So now I can just go create new documents with a new schema, because each document has
55:02
an implicit schema. But if I go back, let me create just a couple of quick documents here.
55:22
Now if I go back to my view, now I can check that. Let me just pull up a random somewhere in here. So now you can see, does everyone see this type equals task? Now in my map function, I can emit only tasks.
55:43
Anything you can do in JavaScript, you can do, oops, and you can't edit in production. You have to go to dev to edit. Anything you can do in JavaScript, you could theoretically embed jQuery in here. I've basically taken a base64 decoder, put it in here,
56:03
and pulled out original strings that have been base64 encoded as a demo. I would never recommend doing that. But now I can check if doc.type equals task, then emit it. So if I save that, and I show the results,
56:24
now you see that I'm only getting the two records that I created. So I've given taxonomy to my documents, even though they don't have it. So I'm republishing to production. So now when I go back to list, hopefully everything should work. And now you see that I have my documents.
56:42
But I want to show one last thing, then I'll take questions. So if I create a new document, and I give it, so if we look back at my list, you see I have 114, 314. Let's say I do 12, 12, 2013, no, 2012.
57:02
So I'm intentionally creating these in the past. So a couple things to demonstrate. Views are eventually consistent. So basically when you create the view, you create an index on all the documents that exist. There are different tuning settings to say that you can force a view to be not eventually
57:21
consistent. I don't have time to demo that, but it's basically you can set a flag that says on a right, make sure it goes to disk. On the view, make sure that you update the index, which is incremental. It's not going to update all of your documents. It's just anything that's changed. And that gives you a fully consistent read. So when I refresh, it shows up.
57:40
So it just took a second for the indexer to kick off and update that. So basically requesting a view triggers the next index of your view. But you can tell the view index first, and then give me a result. But notice that these are not quite in order. 12-12-2012 should be the first task in my list. So the way I solve that problem,
58:02
I can create an index on the date. So if I go back here, we're going to add a new view. And we're going to call this by date. And this is going to be very similar to my all.
58:20
So I'm just going to copy this. So let me make that a little bigger. So now in addition to checking that the type is a task, I want to make sure that, because we're schemaless, I want to have some protection on my index creation.
58:42
I want to make sure that the doc has a due date. I don't want to index a document by due date if it doesn't have a due date. And I can just use JavaScript's implicit null check there. So now I'm emitting the due date.
59:01
So you can think of all these map functions. If you want to think of a SQL analogy, create index. All this is doing is creating indexes on properties inside of documents. So if I show the results, you can see that now I'm ordering correctly by date time. Let me publish this to production.
59:27
And if I come back here and change my method to by date. So now when I refresh this, we should see this order by date.
59:47
So now 12-12-2012 comes first, which coincidentally is the date that Couchbase 2 was launched. One other thing I'll mention that's worth knowing about is
01:00:00
Out on github.com slash Couchbase Labs, there's a much more complete example of using Couchbase with MVC. And this runs against the beer sample database. And I've extensively commented this thing. I wrote like a 40-page tutorial on it. Actually, if you picked up the NDC developer book,
01:00:25
I wrote an article on basically, here's the beer sample database. Here's the view that gets you data out of it. So that's in there. But this has everything from basic CRUD forms that we just looked at. If you wanted to see, it doesn't look like we have any.
01:00:44
If you wanted to see how to do aggregation, this is all in there. If you wanted to see, again, this is github.com slash Couchbase Labs. And there's also geospatial stuff.
01:01:00
So if you wanted to see how to do geospatial indexing, this app goes through some best practices, too. So is everyone familiar with the repository pattern? So I implemented a repository of T. Oops, I'm at zero here. So there's a repository of T. And it's fully commented.
01:01:21
You can see how to create subclasses out of a base repository class, which will then give you access to all of your handling of errors and how to reuse a lot of this code. So there's also one last thing I'll mention. That JavaScript stuff that I was showing you, you can actually not do that and instead use
01:01:43
a framework I wrote called Couchbase Model Views, which you decorate your plain old C Sharp objects with attributes and it'll auto-generate the views for you. So if you wanted to create that all view, a by name query, or that sort of stuff, it'll just automatically generate that.
01:02:01
So I know that was a lot of information, but are there any questions in this framework? Oh, sure. So the sorting, it's ascending by default. You can set descending to false.
01:02:20
There's a parameter. So all the views, the API has things like descending. You can set stale as the parameter to turn off. You can do an exact query by key by passing in a key. So if you wanted to find the user with a last name of x.
01:02:43
All in the query, yep. Question? So multiple buckets, I would generally say there are resources associated with each bucket and there are limitations where you can't cross buckets to get data.
01:03:00
So if you have a document in one and you want to somehow reference that document, you can't do joins or anything like that in a NoSQL database, but with the same client, you can get to multiple documents within a bucket. So there's client affinity to a bucket. So if you create an instance of a, like if you have five
01:03:21
buckets, you're one going to create a lot of client resources. So it's per node, per bucket, 10 connections per server. So that adds up quickly. But more importantly, there are things like indexers. So the thing that actually implements all those design documents, or implement, that thing that actually indexes all those documents, is happening per bucket. So a lot of those resources are expensive.
01:03:41
So the general rule of thumb I always follow is if I would create a database for this in SQL Server, I would create a bucket for it in Couchbase with that type property. So again, it's that convention of including a type property or a doc type property or something.
01:04:01
And that's kind of inherited from CouchDB, where the same sort of general collection of just one thing existed. Yeah, you can, so there's some limits when you set the bucket memory size, it has to be equal, there has to be basically
01:04:22
the same amount of RAM on each node in the cluster, because the sharding is distributed equally. So you can't have one bucket, one node can't have, so if you set it to three gigs, for example, all of your servers have to have three gigs available. So if you had like a 96 gig large instance on Amazon and you wanted to have that coupled with a small instance
01:04:42
with 24 gigs or something, that wouldn't work. But you can upgrade all of the nodes. Question? You can have nested objects. So there's no referential integrity,
01:05:03
so generally the pattern is to store the ID of another document as a property of another document. So you need to combine them manually. And in that beer sample application I showed you, I do walk through how you do master detail. So it's a little tricky, and I actually
01:05:20
walk through that in the developer article that I wrote. Like what? So the comment was about it looks like Lotus Notes. Damien Katz, who is the CTO of Couchbase and the creator of CouchDB, worked on Lotus Notes. So no coincidence, I'm sure.
01:05:43
Question? No, so you specify. The question is, when you handshake to that first node, generally you want to specify more than one node. So if that node isn't available,
01:06:01
you can get to the next one. But once it connects to one node, it gets a list of all the URIs. So if a node goes down, it knows how to get to the next one.
01:06:20
In the config is generally the preferred approach, because it maintains an internal list of nodes to connect to. Question?
01:06:44
You know, I think one of the, so NoSQL actually refers to not only SQL, so I think anyone at Couchbase or in any NoSQL company would probably suggest that it's a complementary technology. SQL will always have a place for data warehousing, for highly transactional systems.
01:07:01
You can mimic sort of after the fact transactional systems, like do verifications after things go wrong, after things are inserted and see if they went wrong. But I definitely think there's room for both. I don't think that anyone's going to stop using SQL because of Couchbase, but they may stop using some of their SQL for Couchbase.
01:07:22
Performances, yeah, performance is definitely a big issue. So Couchbase is probably, this is obviously a somewhat biased opinion, but is generally considered probably the fastest NoSQL database out there. So a good example of what we can achieve, LinkedIn, I'm sure most people know of, they have a four node
01:07:41
cluster. They're doing 400,000 ops per second. Cisco, who has ridiculously fast hardware, has a five node cluster doing one and a half million operations per second. So you can't get that out of SQL Server. You can't get that. You could, it would just cost you a fortune. So for people who need to scale massively and easily
01:08:00
and quickly, one of our biggest success stories is that you guys have draw something. Did everyone, does everyone remember that game, the little Pictionary app? It went from like 3 million to 100 million users in a matter of weeks, and they scaled out on us. So there's, scale is definitely our best story. We have, I think we have just,
01:08:22
we've spent a lot of time in making sure that this thing will grow from one node to 100 nodes and have no downtime. Because you can, you add nodes, take nodes offline without your application having to go offline. Question?
01:08:47
Oh yeah, so cross data center replication is cluster to cluster. That is the standard. But you can, because it's an open interface, you can actually implement other endpoints. But the replication is actually just, I have three nodes in a cluster. I specify that two of them are replicas and one of them
01:09:02
is a primary. So it just, it will replicate automatically for you. You could, yes. Yeah, so if you wanted to take, so a common use case is in the advertising industry, the online advertising industry, where people, they pull data into Couchbase,
01:09:22
pump it out into Hadoop, do some analytics, and pump it back into Couchbase. Any other questions? Thank you.