1 / 27

Introduction to Document Databases with RavenDB

Introduction to Document Databases with RavenDB. David Green @ davidjeet. Agenda. NoSql databases Prereqs CAP Theory Features of Document Databases Features of RavenDB Getting Started – Deployment Raven Studio Code Demo 1 – CRUD + Http API

gmagnus
Download Presentation

Introduction to Document Databases with RavenDB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Document Databases with RavenDB David Green @davidjeet

  2. Agenda • NoSql databases • Prereqs • CAP Theory • Features of Document Databases • Features of RavenDB • Getting Started – Deployment • Raven Studio • Code Demo 1 – CRUD + Http API • Code Demo 2 – MVC3 Template, Indexes, Map-Reduce, Lucene, Http API • Extras

  3. Pre-Reqs: What you need to know • .NET Framework, C# 3.5/4.0 • Basic familiarity with LINQ & lambda expressions • Maybe some JavaScript (if you want to use HTTP API)

  4. NoSQL databases Graph Key-value store Document Object

  5. Document databases • Key/Value: A document database is, at its core, a key/value store with one major exception. • Format: Instead of just storing any blob in it, a document db requires that the data will be store in a format that the database can understand (XML, JSON, Binary JSON, etc.) • Schema Free: A document database is schema free, that is, you don’t have to define your schema ahead of time and adhere to that. • Relationships Not Enforced: It does not, however, support relations. Each document is standalone. There is nothing to enforce relational integrity. • Benefit: The major benefit of using a document database comes from the fact that while it has all the benefits of a key/value store, you aren’t limited to just querying by key. Excerpts from: http://ayende.com/blog/4459/that-no-sql-thing-document-databases

  6. CAP Theory

  7. Example of a schema-less table Books/33 Books/417 Books/59

  8. RavenDB • RavenDB is a document database system • Created by Oren Eini (Ayende Rahein) • Beyond just being your typical database, it is also a web server. • Uses LINQ for querying (i.e. Map-Reduce). • Uses Lucene search engine. • Supported in MVC4, WebForms, Winforms, Console…everything • RavenDB is optimized for reading. (some Document databases optimized for write) • Adheres to some BASE principles: • BasicAvailability • Soft-state • Eventual consistency

  9. Getting Started - Deployment Raven DB has four different methods for deployment: Server mode (console, not to be used in production) IIS Windows service Embedded

  10. Getting Started - Server Mode • Create (or use an existing) a new solution + project that will be using RavenDB. It doesn’t matter what kind of project this is (i.e. console, WinForms, ASP.NET, etc.) • With NuGet package manager, search on “RavenDB” and you can select from: • Raven (Embedded) • Raven (Client) • Raven (Server) • Select the third option “Raven” which will install the server piece in the packages folder of your solution.

  11. Getting Started - Server Mode

  12. RavenStudio(like SSMS) http://localhost:8080/raven/studio.html It’s Silverlight based (make sure you have Silverlight installed) It *sometimes* auto-launches when firing up the console: In Solution Explorer, right-clickOpen File In Windows Explorer Navigate to packages/RavenDB.x.y.zzz/server Create a .cmd file (notepad) with the following line:start Raven.Server.exe --debug –browser Use the .cmd file you just created to launch the console (it will also launch the browser)

  13. Basic CRUD Demo – Music Store • Read (w/o model) • Read (basic) • Read (dynamic index) • Create • Update • Delete

  14. Set “Target Framework” for Console Apps

  15. Advanced Demo – StackExchange • Using a Base Controller (MVC3) • Handling Joins • Map-Reduce • Indexes • Lucene Search Engine • Http API

  16. Relational View of StackExchange

  17. MVC3 Template for RavenDB usage • Can use Singleton Design pattern or Dependency Injection. • Using a base class for the controller (i.e. “RavenController”) • Overriding the OnActionExecuting and OnActionExecuted event.

  18. How to Handle Relationships in RavenDB • Couple of ways to do this: • One common technique is to use .Include<T>() method. • Depending on the scenario, de-normalization can be used instead.

  19. Indexes • Two types of Indexes in RavenDB: • Static • Dynamic There are a few reasons why to prefer static indexes over dynamically created ones: High latency - Index creation is not a cheap process, and may take a while to execute. Since dynamic indexes are created on the fly on first user query, first non-stale results may take a long time to return. Since dynamic indexes are created as temporary indexes, this is going to be a performance issue on first run. Flexibility - Static indexes expose much more functionality, like custom sorting, boosting, Full Text Search, Live Projections, spatial search support, and more.

  20. Map- Reduce Example: Creating an index called Posts/TagCount Map from post in docs.Posts from Tag in post.Tags select new { Tag, Count = 1 } Reduce from result in results group result by result.Tag into g select new { Tag = g.Key, Count = (int)g.Sum(x=>x.Count) }

  21. Lucene Syntax:http://www.lucenetutorial.com/lucene-query-syntax.html • Examples: • With “Posts” Collection: • (PostTypeId: 1 AND Title: *relativity*) • (PostTypeId: 1 AND AnswerCount: 6) • Title: “particle energy"~4 //proximity search example • With “Users” Collection: • DisplayName: David~0.4 // fuzzy search example • DisplayName: David~0.8

  22. Extras • Additional Resources • Deleted Scenes • Behind the camera with David Green

  23. RavenDB Deployment – Embedded Mode

  24. Resources Helpful Tools • Couple tools out there – Some are RavenDB specific, others like Fiddler and LinqPad also work well. Helpful Links • For setup/install: • http://blogs.hibernatingrhinos.com/5/ravendb-in-practice-part-1-an-introduction-to-ravendb • http://ravendb.net/docs/intro/quickstart/adding-ravendb-to-your-application • http://www.codecapers.com/post/Using-RavenDB-with-ASPNET-MVC.aspx • http://msdn.microsoft.com/en-us/magazine/hh547101.aspx • Best Intro: • http://ravendb.net/docs/client-api • http://ravendb.net/docs/http-api • http://ravendb.net/docs/server/deployment • http://ravendb.net/kb/3/using-ravendb-in-an-asp-net-mvc-website • http://blogs.hibernatingrhinos.com/3073/ravendb-in-practice-part-2-using-the-client-api • http://www.codeproject.com/Articles/74322/RavenDB-An-Introduction • http://www.codecapers.com/post/Using-RavenDB-with-ASPNET-MVC.aspx • http://tech-rash.blogspot.com/2012/02/is-raven-db-all-its-cracked-up-to-be.html (review) • Relations/joins: • http://daniellang.net/how-to-handle-relations-in-ravendb/ • http://old.ravendb.net/faq/includes

  25. MongoDB vs. CouchDB vs. RavenDB Taken from: http://weblogs.asp.net/britchie/archive/2010/08/17/document-databases-compared-mongodb-couchdb-and-ravendb.aspx

  26. Pricing/features for RavenDB 1.2 RavenDB is being split into three editions: RavenDB Basic - monthly subscription only (5$ - 512 MB db size limit, 5 databases limit. 10$ - 1GB db size limit, 10 databases limit). A single indexing thread, 2 GB memory limit.  RavenDB Standard - what we have with RavenDB right now. 6 CPU + 12 GB limit. 999$ for a one time payment - 18 months upgrade protection.  399$ for a yearly subscription - as long as you have a current subscription, you can use the software and get free upgrades. 39$ for a monthly subscription  RavenDB Enterprise - per core licensing. No limits on CPU / Mem. Additional features, detailed in the previous email.  Per core pricing (# of cores == Environment.ProcessCount) is 699$ per core . 18 months upgrade protection.  299$ per core per year. 79$ per core per quarter  In addition to that we have two additional licensing modes:1) OEM - embedded only - 1599$ per developer for the first year.  999$ per developer for renewal. 2) Scaleout- bundles of 10, 20 and 50 licenses for scaleout / sharding scenarios, which are sold at a reduced cost.  Development will continue to be free! (emphasis added).

More Related