Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to RavenDB

Jaime
February 28, 2014

Introduction to RavenDB

An introductory view into the world of NoSQL and RavenDB.

Jaime

February 28, 2014
Tweet

More Decks by Jaime

Other Decks in Programming

Transcript

  1. Edgar Allan Poe
    presents
    The Raven

    View Slide

  2. Once upon a midnight dreary, while I pondered, weak and weary,
    Over many a quaint and curious volume of forgotten lore--
    While I nodded, nearly napping, suddenly there came a tapping,
    As of some one gently rapping, rapping at my chamber door.
    "'Tis some visiter," I muttered, "tapping at my chamber door--
    Only this and nothing more."

    View Slide

  3. …just kidding…

    View Slide

  4. Jaime González García
    Enthusiastic Software developer!
    Works at Medius R&D building a SPA...
    ... but also started jaimegonzalezgarcia.com
    Blogs at barbarianmeetscoding.com
    likes...
    fantasy
    sci-fi
    drawing
    Malin ???

    View Slide

  5. Contents
    • NoSQL?
    • What is RavenDB?
    • RavenDB .NET API
    • RavenDB REST API
    • Installing RavenDB
    • Replication and Sharding

    View Slide

  6. Nosql

    View Slide

  7. In the beginning… the year
    1970 of our Lord
    … 20 years of kicking ass…
    Edgar Frank Codd

    View Slide

  8. In the beginning…

    View Slide

  9. 2000
    BigTable Dynamo
    2009 Nosql

    View Slide

  10. What is NoSql today?
    • Big term used to refer to all non relational DBs (RDMBS’s)
    • Big hype
    • In general:
    • No relational
    • No schema
    • High availability and scalability (Web Scale)
    • Eventual consistency
    • No SQL (generally)
    …just like html5…
    Villaine hipsters!

    View Slide

  11. Why Nosql ? Why Document Stores?
    • Simplicity
    • Developer friendly
    • No impedance mismatch (SQL != OOD)
    • No schema, less friction
    • Scalability: replication and sharding
    • Great APIs
    • Right tool for the job
    Databases for
    developers??

    View Slide

  12. Why Sql ? :-)
    • ACID
    • Consistency
    • More mature
    • More Common Competence
    • Better tooling
    • Can handle all kinds of queries
    • SQL

    View Slide

  13. Types of nosql databases?
    Graph Databases
    http://nosql-database.org/
    Wide Column Stores
    Document Stores
    Key value Stores

    View Slide

  14. Ravendb
    basics

    View Slide

  15. Ravendb
    • Document Database
    • No schema
    • Store objects as JSON documents
    • Query using LINQ
    • Built-in REST API
    Wonderfultastic!

    View Slide

  16. Ravendb
    • ACID document transactions
    • BASE index querying
    • Self-optimizes based on usage
    • High scalability
    • Replication and sharding out of the box
    • Safe by default

    View Slide

  17. Ravendb Management Studio (RDBMS)
    • Silverlight application
    • Access via browser where RavenDB server is hosted

    View Slide

  18. Ravendb documents
    • An object stored in RavenDB is called a document
    • Documents need not be flat unlike rows in RDBMS
    • Persisted as JSON

    View Slide

  19. Ravendb documents
    • Documents can be [logically] grouped in collections
    • Collections are defined as metadata
    • Indexes filter by collections

    View Slide

  20. Ravendb documents
    • Each document has its own unique document ID
    • If we try to store two entities with the same id -> overwrite
    • By convention ID = collectionName/entityId (users/1)
    • By default entity id’s are generated (auto-incremented)

    View Slide

  21. Ravendb documents
    • Every document has metadata attached

    View Slide

  22. Modeling in Ravendb
    • Documents are not flat, you can store complex structures
    • RavenDB is not relational
    • A document is an independent entity
    • Include all details you need within the document
    • This is good for sharding
    • References are not enforced by the DB
    • If following DDD, an Aggregrate is a document
    • This pretty much enforces DDD uses of aggregates from the dB
    • Use aggregate to enforce invariants to store information safely

    View Slide

  23. View Slide

  24. demo
    Ravendb management studio

    View Slide

  25. Ravendb
    .net api

    View Slide

  26. Ravendb .net api
    • Unit of Work
    • Change tracking, transactions, batching, etc
    • Feels like Entity Framework or NHibernate
    • IDocumentSession (unit of work)
    • IDocumentStore (session factory, singleton)
    • Query with LINQ
    • Works with pure POCOs
    • Available on NuGet

    View Slide

  27. A Poco’s life in Ravendb
    C# class
    Public class Raven
    {
    public string Name {get;set;}
    }
    POCO
    var myCuteRaven= new Raven {Name = “Kiwi”}
    (Plain Old CLR Object)
    Document
    instantiate ravens/1
    {
    “Name”: “Kiwi”
    }

    View Slide

  28. Ravendb .net api – Querying
    • Every query uses and index
    • Static indexes persisted in the DB
    • Dynamic indexes created on the fly
    • Based on the queries that you do
    • Self-optimization based on usage
    • Eventual Consistency
    • Stale better than offline
    • BASE (Basically Available, Soft State, Eventual Consistency)

    View Slide

  29. Ravendb .net api – Querying

    View Slide

  30. Ravendb .net api – Other cool stuff
    • Uses Lucene as search engine
    • Can easily add attachments to documents
    • Profiling
    • Fully customizable
    • cache
    • Max number of request per session
    • Key generator
    • conventions
    • etc...

    View Slide

  31. demo

    View Slide

  32. Ravendb
    Rest api

    View Slide

  33. Ravendb Rest api
    • Documents in RavenDB feel a lot like resources...
    • Built-in REST api for CRUD operations over documents!
    You could run your whole
    single page application against
    Ravendb!

    View Slide

  34. demo
    Get started with Ravendb Rest api

    View Slide

  35. Ravendb
    Intalling

    View Slide

  36. Installing Ravendb
    • Client-Server
    • Install and start the service manually
    • Install as a windows service
    • Deploy it on IIS
    • DaaS (Database as a Service) (IaaS )
    • Embedded in your .NET Application

    View Slide

  37. Installing Ravendb

    View Slide

  38. Extend Ravendb via Bundles
    • Compression
    • Encryption
    • Expiration
    • Versioning
    • Quotas
    • Periodic Backups
    • Authorization
    • etc
    http://ravendb.net/docs/2.5/server/extending/bundles

    View Slide

  39. demo
    Installing Ravendb

    View Slide

  40. Ravendb
    With replication and sharding
    Scaling out

    View Slide

  41. Scaling Ravendb
    • Replication and Sharding out of the box
    • Sharding
    • Native
    • Partition contents of a ravendb database across several machines
    • Replication
    • Replicate contents of a ravendb database
    • As a bundle
    • Can replicate to SQL Server
    http://ravendb.net/docs/2.5/server/scaling-out

    View Slide

  42. References
    And code samples

    View Slide

  43. Github
    https://github.com/Vintharas/TheRavenDB
    https://github.com/Vintharas/BLooDandSTeeL

    View Slide

  44. View Slide

  45. Nosql books

    View Slide

  46. Ravendb books

    View Slide

  47. On NoSql
    • NoSQL databases Explained
    • http://www.mongodb.com/learn/nosql
    • Pluralsight - NoSQL the big picture
    • http://pluralsight.com/training/Courses/TableOfContents/nosql-big-pic
    • Pluralsight - Understanding NoSQL
    • http://pluralsight.com/training/Courses/TableOfContents/understanding-nosql

    View Slide

  48. Ravendb documentation
    • RavenDB Documentation
    • https://ravendb.net/docs
    • RavenDB YouTube channel
    • http://www.youtube.com/playlist?list=PL7E1E1A49999CB0F5

    View Slide

  49. View Slide

  50. Ravendb courses
    • Pluralsight - Introduction to RavenDB
    • http://pluralsight.com/training/Courses/TableOfContents/ravendb
    • Pluralsight - A Tour of RavenDB (with Ayende!!)
    • http://pluralsight.com/training/Courses/TableOfContents/tekpub-ravendb

    View Slide

  51. Thank you.
    y u so sad?!?
    Thank you!

    View Slide