thinking in a document centric world with ravendb by nick josevski

53
Thinking in a document centric world with RavenDB

Upload: nick-josevski

Post on 27-Jan-2015

113 views

Category:

Technology


3 download

DESCRIPTION

RavenDB presenation given at ALT.NET Melbourne Feb 2014

TRANSCRIPT

Page 1: Thinking in a document centric world with RavenDB by Nick Josevski

Thinking in a document centric world

with RavenDB

Page 2: Thinking in a document centric world with RavenDB by Nick Josevski

There’s got to be a better way,

Somewhere over the…

Page 3: Thinking in a document centric world with RavenDB by Nick Josevski

We’re off to see the Wizard

Page 4: Thinking in a document centric world with RavenDB by Nick Josevski
Page 5: Thinking in a document centric world with RavenDB by Nick Josevski

What is RavenDB?

• It is a Document Store• Built with .NET• Fast• Easy to use / program against• Currently only runs on Windows• If you’re wondering it supports MSDTC• Open source

Page 6: Thinking in a document centric world with RavenDB by Nick Josevski

SOME BASIC CONCEPTS

Page 7: Thinking in a document centric world with RavenDB by Nick Josevski

CAP Theorem

• Consistency• Availability• Partition Tolerance

• When you suffer a network partition between stores.• You decide how much Consistency OR Availability you would

like to have.

Page 8: Thinking in a document centric world with RavenDB by Nick Josevski

Documents are not flat

• A single document can be a complex object graph.

• It’s no longer a challenge to store your data• You’re no longer in a relational world– Schema-free data store– Does not mean chaos as some would lead you to

believe

More info on this at: http://ravendb.net/docs/theory/document-structure-design

Page 9: Thinking in a document centric world with RavenDB by Nick Josevski

Eventual Consistency

• In RavenDB– Writes occur against the document store.– Queries occur against the index store.– Single Load operations go directly to the

document store.

• RavenDB is more consistent than others• Also: not all viewers of data should be

considered equal.

Page 10: Thinking in a document centric world with RavenDB by Nick Josevski

Eventual Consistency

• Step 1 : Optimise for reading,

• Step 2: by prioritising Availability higher than Consistency

• Step 3: (Index is stale)

• Step 4: Profit

Page 11: Thinking in a document centric world with RavenDB by Nick Josevski

GETTING STARTED

Page 12: Thinking in a document centric world with RavenDB by Nick Josevski

Installation

Page 13: Thinking in a document centric world with RavenDB by Nick Josevski

Raven Management Studio

Page 14: Thinking in a document centric world with RavenDB by Nick Josevski

USING RAVEN DB

Page 15: Thinking in a document centric world with RavenDB by Nick Josevski

Using Raven in your .NET Code

Page 16: Thinking in a document centric world with RavenDB by Nick Josevski

Just like any (good) ORM

• Persist Document

• Loading

• Queries

Page 17: Thinking in a document centric world with RavenDB by Nick Josevski

Unit of Work Pattern

• With IDocumentSession– Open a session of work– Make changes in memory– Persist changes

Page 18: Thinking in a document centric world with RavenDB by Nick Josevski

Search Capabilities

• Search is delegated to Lucene.NET– Full text indexing

Page 19: Thinking in a document centric world with RavenDB by Nick Josevski

FETCH / QUERY

Page 20: Thinking in a document centric world with RavenDB by Nick Josevski

Session.Include

• The simplest way to start retrieving documents and other associated documents

Page 21: Thinking in a document centric world with RavenDB by Nick Josevski

Session.Query

• It is just LINQ• Pagination via:– .Skip() and .Take()

Page 22: Thinking in a document centric world with RavenDB by Nick Josevski

Session.Customize

• As part of a query retrieve associated documents

Page 23: Thinking in a document centric world with RavenDB by Nick Josevski

Safe by Default

• 3 magic numbers to help you out– Default page size limit 128– Take(n > 1024) is still 1024

– Requests 30 • Why so many calls?

• Overridable via configuration, for those SELECT * FROM addicts

Page 24: Thinking in a document centric world with RavenDB by Nick Josevski

Transformers

• Server side projections – with the ability load data from other documents– RavenDBs true power shining through

Page 25: Thinking in a document centric world with RavenDB by Nick Josevski

Simple Transformer

Page 26: Thinking in a document centric world with RavenDB by Nick Josevski

Real World Example

Page 27: Thinking in a document centric world with RavenDB by Nick Josevski

Real World Example

Page 28: Thinking in a document centric world with RavenDB by Nick Josevski

INDEXES

Page 29: Thinking in a document centric world with RavenDB by Nick Josevski

Indexes

• With the power of schema-less store• Comes great (some) responsibility• Raven doesn’t know about fields on your

document by default• So if you haven’t set up indexes raven will help

you out

Page 30: Thinking in a document centric world with RavenDB by Nick Josevski

Indexes

• Extend Abstract Index Creation Task

Page 31: Thinking in a document centric world with RavenDB by Nick Josevski

Map / Reduce

• Just like previous examples except there’s a reduce component

• Most trivial examples is summing up totals/counts of items

Page 32: Thinking in a document centric world with RavenDB by Nick Josevski

Map / Reduce

Page 33: Thinking in a document centric world with RavenDB by Nick Josevski

Multi-Map

• Querying Unlike Documents• To build up something that doesn’t exist• We’re working with documents– No need for left/inner/outer/right/middle joins

Page 34: Thinking in a document centric world with RavenDB by Nick Josevski

Multi-Map

Page 35: Thinking in a document centric world with RavenDB by Nick Josevski

Real World Example

Page 36: Thinking in a document centric world with RavenDB by Nick Josevski

PROFILING

Page 37: Thinking in a document centric world with RavenDB by Nick Josevski

Profiling is first class

• Fiddler is your friend

Page 38: Thinking in a document centric world with RavenDB by Nick Josevski

• For your ASP.NET MVC App1.

2. In Global.asax.cs

3. In _layout.cshtml

• Demo app up at: https://github.com/NickJosevski/ravendb-presentation

ASP.NET Profiling Integration

Page 39: Thinking in a document centric world with RavenDB by Nick Josevski

ASP.NET Profiling Integration

Page 40: Thinking in a document centric world with RavenDB by Nick Josevski

REAL WORLDMore in the

Page 41: Thinking in a document centric world with RavenDB by Nick Josevski

Raven in Apps

Page 42: Thinking in a document centric world with RavenDB by Nick Josevski

Structure of our Documents

• Varies and has been tuned for each use case• But can be summarised into 3 types

Page 43: Thinking in a document centric world with RavenDB by Nick Josevski

Network of Documents

Page 44: Thinking in a document centric world with RavenDB by Nick Josevski

Single Documents

Page 45: Thinking in a document centric world with RavenDB by Nick Josevski

Single Documents

Page 46: Thinking in a document centric world with RavenDB by Nick Josevski

Parent & Child Documents

Page 47: Thinking in a document centric world with RavenDB by Nick Josevski

4th type and no longer used

• When we started with Raven• We started down a path of “Summary”

Documents – Which became a problem to maintain

• Replaced with Transformers outputting SummaryDTOs

Page 48: Thinking in a document centric world with RavenDB by Nick Josevski

Deploying Indexes/Transformers

Page 49: Thinking in a document centric world with RavenDB by Nick Josevski

IOC Container Registration

Page 50: Thinking in a document centric world with RavenDB by Nick Josevski

Document Conventions

Page 51: Thinking in a document centric world with RavenDB by Nick Josevski

Projectors

Page 52: Thinking in a document centric world with RavenDB by Nick Josevski

More Info / Sources

• http://ravendb.net/• Tekpub (series now on Pluralsight)• RavenDB High Performance by Brian Ritchie• NoSQL video from Martin Fowler– http://www.youtube.com/watch?v=qI_g07C_Q5I

• Reach out to me Nick Josevski– 1st video recording of this:– http://www.youtube.com/watch?v=u3kUpFlf76M

Page 53: Thinking in a document centric world with RavenDB by Nick Josevski

Thanks

• Questions?