Slide 1

Slide 1 text

Introducing RavenDB Agile Persistence in .Net Johnny Graber

Slide 2

Slide 2 text

About Johnny Graber •Software Engineer - Swiss Medical Association •Twitter: @j_graber •E-Mail: [email protected] •Blog: ImproveAndRepeat.com

Slide 3

Slide 3 text

Today’s Main Topics •NoSQL •RavenDB •Agile Persistence

Slide 4

Slide 4 text

Demo Accessing RavenDB How simple is it to access RavenDB? Demo

Slide 5

Slide 5 text

NoSQL?

Slide 6

Slide 6 text

No SQL

Slide 7

Slide 7 text

Not only SQL

Slide 8

Slide 8 text

Polyglot Persistence

Slide 9

Slide 9 text

Relational Databases aren’t Obsolete

Slide 10

Slide 10 text

Great for •Optimized Writes •Minimal Storage Footprint •Flexible Querying

Slide 11

Slide 11 text

But •Mostly Reads in Our Applications •Storage Costs (Almost) Nothing •Hard to Scale

Slide 12

Slide 12 text

NoSQL Provides Solutions

Slide 13

Slide 13 text

Main Types of NoSQL •Key / Value Store •Graph Database •Column Database •Document Store

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

RavenDB •2nd Generation Document Database •Built on .Net •Schema Free

Slide 16

Slide 16 text

Some RavenDB Features •Safe by Default •Supports Transactions (ACID) •Best Practices Built in

Slide 17

Slide 17 text

A Document in RavenDB •Self-Contained •Independent •Redundant Data (History)

Slide 18

Slide 18 text

A Document in RavenDB

Slide 19

Slide 19 text

Running RavenDB •Standalone Server •Part of Your Web-Application •Embedded Mode

Slide 20

Slide 20 text

Installing RavenDB

Slide 21

Slide 21 text

RavenDB Studio •Look Into the Database •Generate Sample Data •Administration Tools

Slide 22

Slide 22 text

Connect to RavenDB •.Net Client Install-Package RavenDB.Client •HTTP API

Slide 23

Slide 23 text

Demo HTTP API / RavenDB Studio Can you use RavenDB without .Net? Demo

Slide 24

Slide 24 text

Querying RavenDB var books = from books in session.Query() where books.Title.StartsWith("Raven") select books; var book = session.Load("books/1");

Slide 25

Slide 25 text

Indexes in RavenDB •All Queries Need an Index •Static or Dynamic •Created in Background (Stale Index)

Slide 26

Slide 26 text

Challenges for Index Creation •Schema Free Data •Fixed Structure to Find Data •Closing the Gap with Map/Reduce

Slide 27

Slide 27 text

Map/Reduce This is probably the most common error that people make with any sort of data access technology. "Just give me the whole thing, I'll make sense of it on the client side." In the RDBMS world, this would be expressed as "SELECT * FROM Orders". The problem with such queries is they can potentially… Map Reduce

Slide 28

Slide 28 text

Demo Index Creation How hard can it be? Demo

Slide 29

Slide 29 text

Licencing RavenDB •AGPL for Open Source Projects •Commercial Licence: 399$/Year/Instance •RavenHQ: Starting at 10$/Month

Slide 30

Slide 30 text

Agile Persistence

Slide 31

Slide 31 text

Development Today •Agile Approach •Embrace Change •Fail Fast

Slide 32

Slide 32 text

Except in the Persistence Layer •First Time Right •Hard to Change •Don’t Touch

Slide 33

Slide 33 text

“When the Database must be correct the first time, every part of the application must be known at the beginning”

Slide 34

Slide 34 text

“Persistence should be an application detail”

Slide 35

Slide 35 text

Domain-Driven Design •Aggregates •Bounded Context •Entity or Value Object

Slide 36

Slide 36 text

Benefits of Following DDD Principles •History of Documents •Complete Change Tracking •Optimised Data Access

Slide 37

Slide 37 text

Command Query Responsibility Segregation (CQRS) •Commands Modify State •Queries Answer Questions •Keep Them Apart

Slide 38

Slide 38 text

CQRS for Fast Applications

Slide 39

Slide 39 text

CQRS and RavenDB •HTTP API (REST) •When Unauthenticated Only Allow Read •Done

Slide 40

Slide 40 text

TDD and RavenDB •Don’t Abstract an Abstraction Layer! •Use In-Memory Mode •It’s Fast Enough

Slide 41

Slide 41 text

Changing Documents •Easily Done •Know the Impacts •Worst Case: Full DB Update

Slide 42

Slide 42 text

Start with RavenDB •Hacking •Pet Projects •Prototypes •Spikes

Slide 43

Slide 43 text

*Try* This at Home NOT in Production!

Slide 44

Slide 44 text

Use RavenDB in Production •When You Know it •RavenDB Solves Your Problems •Have Time to Learn Even More

Slide 45

Slide 45 text

What’s Missing •Authorisation & Authentication •Bulk Inserts •Paging •Sharding

Slide 46

Slide 46 text

More on RavenDB •RavenDB.net •Tekpub.com •ImproveAndRepeat.com

Slide 47

Slide 47 text

More on CQRS & Polyglot Persistence •Martin Fowler: http://martinfowler.com/bliki/CQRS.html •Jimmy Bogard: Real World Polyglot Persistence http://vimeo.com/68320412

Slide 48

Slide 48 text

Questions? [email protected]

Slide 49

Slide 49 text

Thank You!

Slide 50

Slide 50 text

Demo Accessing RavenDB How simple is it to access RavenDB?

Slide 51

Slide 51 text

Connect to RavenDB using (var documentStore = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "Demo" }.Initialize()) using (var session = documentStore.OpenSession()) { // Your Code }

Slide 52

Slide 52 text

The Book Class public class Book { public string Id { get; set; } public string Title { get; set; } public string ISBN { get; set; } public int Pages { get; set; } }

Slide 53

Slide 53 text

Add Data to Session var book = new Book { Title = "RavenDB Intro", ISBN = "1", Pages = 200 }; session.Store(book); session.SaveChanges();

Slide 54

Slide 54 text

Querying RavenDB var books = from books in session.Query() where books.Title.StartsWith("Raven") select books; var book = session.Load("books/1"); Back

Slide 55

Slide 55 text

Demo HTTP API / RavenDB Studio Can you use RavenDB without .Net?

Slide 56

Slide 56 text

HTTP API: Create Document curl --header "Raven-Entity-Name: Books" -X PUT http://localhost:8080/databases/demo/docs/books/4 -d "{'Title':'HTML Collection', 'ISBN':'123-4','Pages':50}"

Slide 57

Slide 57 text

Result

Slide 58

Slide 58 text

HTTP API: Patch curl -X PATCH http://localhost:8080/databases/demo/docs/books/4 -d "[{ Type: 'Set', Name: 'Pages', Value: 1000}]"

Slide 59

Slide 59 text

Result Back

Slide 60

Slide 60 text

Demo Index Creation How hard can it be?

Slide 61

Slide 61 text

Creating an Index

Slide 62

Slide 62 text

Query the Index

Slide 63

Slide 63 text

Query the Index (HTTP API) Back