Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

24
Building Distributed Systems with RavenDB Oren Eini / Ayende Rahien Hibernating Rhinos [email protected]

description

RavenDB is: No SQL Document Database .NET / JVM / Node.JS / Python / REST / etc clients High performance Scalable & distributed Safe by default ACID And those are just the highlights…

Transcript of Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Page 1: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Building Distributed Systems with

RavenDB Oren Eini / Ayende Rahien

Hibernating [email protected]

Page 2: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Distributed systems look like…

Page 3: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Where do I go?

Your distributed system…

Page 4: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

RavenDB is…

• No SQL Document Database• .NET / JVM / Node.JS / Python / REST / etc clients• High performance• Scalable & distributed• Safe by default• ACID

• And those are just the highlights…

Page 5: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Use RavenDB for?

• Saga state• Timeout data• Subscription storage• Deduplication• Service Control

Page 6: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Use RavenDB for?

What about you!?

Entities & Aggregates

Complex object graphs

Static aggregation via map/reduce

Endpoint specific database

Page 7: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Distributed Data: the wrong way

Page 8: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Sharing data

Page 9: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Distributed data, properly!

HR Sales

Manufacturing

Page 10: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Inside an endpoint

Sales

Q

Msg handlers

Page 11: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Inside an Endpoint’s RavenDB Server

• Sales DB – all the data for this endpoint• HR DB, Mfg DB – Relevant data for this endpoint from another

location

• Physical separation of data. • Clear data ownership• Isolation

Page 12: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Data distribution

• RavenDB Replication• SQL Replication• Background ETL processes• Dedicated messages• Clear data ownership• What about duplication?

Page 13: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

CQRS: The world via events

• Endpoints send event messages to subscribers.• Subscribers use events to create a view of the world that pertain to

their needs.• ShippmentArrivedEvents means to that we can increase our stock levels.

• How does it work with RavenDB?• Store events as messages.• Process via streams or via map/reduce.

Page 14: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Trivial example

• OrderProcessedEvent – generated by Fulfillment BC• OrderId• CustomerId• TotalAmount• Lines (product, quantity, etc)

• In Sales endpoint, need to know how much customer bought and what.

Page 15: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Map/reduce to the rescue

// mapfrom e in docs.OrderProcessedEventsfrom l in e.Linesselect new {

e.CustomerId, e.OrderDate.Year,l.Product,l.Count

}

// reducefrom r in results group r by new { r.CustomerId, r.Product, r.Year } into gselect new {

g.Key.CustomerId,g.Key.Year,g.Key.Product,Count = g.Sum(x=>x.Count)

}

Page 16: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Answers?

• Immediate (pre-computed)• Which customers bought which products this year?• Which customer didn’t buy product they previous bought?• Etc…

Page 17: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

High availability

• RavenDB Replication

• Zero to crash in…

Page 18: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Load balancing

Page 19: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

RavenFS

• Distributed, replicated file system• Large files• Many files• Optimized replication support

Page 20: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

RavenFS & The Data Bus

• Source code: http://goo.gl/51MRWG

• Better (explicit)• Upload to Raven FS on endpoint #A• Replicate transparently to endpoint #B• Get notified & process file.

Page 21: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Small tricks

• My sagas are in RavenDB…• What can I do with that?

Page 22: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Out of the box with Service Insight

Page 23: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

More interesting, reporting on top of your sagas…

• SQL Replication to dedicated reporting database• Map/Reduce on your sagas.• Live view of everything that goes on.

• Note, separate licensing

Page 24: Building Distributed Systems with RavenDB NSCBcon NY by Oren Eini & Ayende Rahien

Questions?