SlideShare a Scribd company logo
Lessons from theTrenches
Dan Bishop
RavenHQ
dbishop@ravenhq.com
github.com/bishbulb
twitter.com/bishbulb
Typical Project Lifecycle
Technical
Discovery
Convince
Stakeholders
Prototype Iterate
Launch
MVP
Iterate
Life is good! Life is good,
right?
Reality Sets In
โ€ข Business is not โ€œfinishedโ€ with the MVP solution
โ€ข Users are never satisfied
โ€ข User hacks are conceived and proliferated
โ€ข Small gaps grow into chasms
โ€ข Production support issues start coming in
โ€ข Things arenโ€™t shiny anymore
Data Conversions
โ€ข Properties are added and removed
โ€ข Data types change
โ€ข Class names and namespaces change
โ€ข Documents are split or merged
โ€ข Indexes change
Data Conversions โ€“ Adding Properties
public class OrderDelivery {
public string Id { get; set; }
public string Address { get; set; }
public DateTime DeliveryDate { get; set; }
}
{
"Address": "100 First St, NY, NY",
"DeliveryDate": "2016-05-30T12:30:00"
}
public class OrderDelivery {
public string Id { get; set; }
public string Address { get; set; }
public DateTime DeliveryDate { get; set; }
public bool Expedited { get; set; }
}
Data Conversions โ€“ Adding Properties
public class OrderDeliveriesIndex : AbstractIndexCreationTask<OrderDelivery>
{
public OrderDeliveriesIndex()
{
Map = docs =>
from doc in docs
select new
{
doc.Address,
doc.DeliveryDate,
doc.Expedited
};
}
}
Data Conversions โ€“ Adding Properties
var expeditedDeliveries = session
.Query<OrderDelivery, OrderDeliveriesIndex>()
.Where(x => x.Expedited);
if (expeditedDeliveries.Count > 10) {
// email delivery manager
}
Javascript Patching
var result = documentStore.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
new IndexQuery
{
Query = "Tag: OrderDeliveries"
},
new ScriptedPatchRequest
{
Script = "this.Expedited = true;"
},
new BulkOperationOptions
{
AllowStale = false
});
result.WaitForCompletion();
Javascript Patching
var result = documentStore.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
new IndexQuery
{
Query = "Tag: OrderDeliveries"
},
new ScriptedPatchRequest
{
Script = @"
var customerLookup = JSON.parse('customers');
this.Expedited = customerLookup[this.CustomerId].IsPreferred;",
Values = new Dictionary<string, object>
{
{ "customers", JsonConvert.SerializeObject(customers) }
}
});
result.WaitForCompletion();
Javascript Patching
โ€ข Patch scripts always run against an index
โ€ข Make patch scripts idempotent
โ€ข Consider rollback strategy
โ€ข Split changes into multiple releases
โ€ข Debugging
โ€ข Test in the Studio, use output() function
โ€ข View patch progress in RavenDB 3.5
Data Conversions โ€“ Removing Properties
โ€ข Safe by default
โ€ข Properties in the underlying document are retained
documentStore.Conventions.PreserveDocumentPropertiesNotFoundOnModel = true;
โ€ข Clutter by default
โ€ข Keep track of the properties being removed
โ€ข Run Javascript patch scripts in the next release to remove the
properties
You Want All the Data?
โ€ข Raven intentionally makes this hard with the normal APIs
โ€ข Indexes can be stale, query results limited to 1024 results
โ€ข Streaming to the rescue
var results = session.Advanced.Stream<OrderDelivery>("orderdeliveries-");
session.Advanced.LoadStartingWith<OrderDelivery>("orderdeliveries-",
start: 0, pageSize: 1000);
var query = session.Query<OrderDelivery, OrderDeliveriesIndex>()
.Where(x => !x.Delivered);
var results = session.Advanced.Stream(query);
โ€ข Other tips
session.Advanced.MaxNumberOfRequestsPerSession = int.MaxValue;
Semantic Document Identifiers
โ€ข Identifiers that have embedded data/context
โ€ข employees/1/deliveryroutes/2016-06-01
โ€ข Prevents logical duplicates
โ€ข Enables multi-load with one round-trip
โ€ข employees/1/preferences
โ€ข employees/1/workschedule
โ€ข deliveryroutes/2016-06-01/employees/1
โ€ข Enables you to bypass indexes altogether
โ€ข Example: Get all delivery routes for a particular day
LoadDocument
Manager
Employee1 Employee2 EmployeeN
public EmployeesIndex()
{
Map = employeees =>
from employee in employeees
let manager = LoadDocument<Manager>(employee.ManagerId)
select new
{
employee.Id,
ManagerName = manager.Name
};
}
LoadDocument
Manager
CompanyVehicle
public CompanyVehiclesIndex()
{
Map = vehicles =>
from vehicle in vehicles
let manager = LoadDocument<Manager>(vehicle.ManagerId)
select new
{
vehicle.Id,
ManagerName = manager.Name
};
}
LoadDocument
โ€ข One to many relationships could cause problems
โ€ข Only when updating the document that has many other
documents referencing it
โ€ข One to one relationships are fine
โ€ข Look for alternatives
โ€ข Transformers
โ€ข Data duplication
Auto vs Static Indexes
โ€ข Auto indexes are great for prototyping
โ€ข Consider the implications
<appSettings>
<add key="Raven/CreateAutoIndexesForAdHocQueriesIfNeeded" value="false" />
</appSettings>
โ€ข Indexes are resource intensive
โ€ข Be aware of the indexes you have
WaitForNonStaleResults
โ€ข Gives you up-to-date results from an index
โ€ข Dealing with CRUD views
โ€ข Make the writer wait for indexes, not the reader
var results = session
.Query<OrderDelivery, OrderDeliveriesIndex>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow());
Consistency Issues
โ€ข ACID provides specific guarantees
โ€ข DistributedTransactions
โ€ข DTC commit and rollback happen in a separate thread from updates
โ€ข Rather than locking the underlying documents, Raven will allow you to
access them but will return an HTTP 203 Non-Authoritative response
โ€ข Scenario: NServiceBus processing chain of messages
UpdateUserProfile ConfirmPhoneNumber
session.Advanced.AllowNonAuthoritativeInformation = false;
Replication Failover
Create Order
Upgrade to Expedited Delivery
Schedule Delivery Failover to
secondary node
โ€ข Consider multi-transaction business workflows
โ€ข What happens if the Raven client fails over to another node
midway through the processing sequence?
Replication Failover
โ€ข Consider the risk/reward of allowing automatic failover
โ€ข Manual failover is an option
โ€ข Secondary nodes are treated as โ€œhot standbyโ€ nodes
โ€ข Mix-and-match failover behaviors
โ€ข Consider SLAs and business needs when deciding on
failover strategies
โ€ข These tradeoffs are not specific to RavenDB
โ€ข All distributed systems have similar challenges
Questions
Ad

More Related Content

What's hot (19)

MongoDB at community engine
MongoDB at community engineMongoDB at community engine
MongoDB at community engine
mathraq
ย 
Why Wordnik went non-relational
Why Wordnik went non-relationalWhy Wordnik went non-relational
Why Wordnik went non-relational
Tony Tam
ย 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDB
Andrew Siemer
ย 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
indiver
ย 
Document Databases & RavenDB
Document Databases & RavenDBDocument Databases & RavenDB
Document Databases & RavenDB
Brian Ritchie
ย 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014
Ike Ellis
ย 
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
NCCOMMS
ย 
SenchaCon 2016 - How to Auto Generate a Back-end in Minutes
SenchaCon 2016 - How to Auto Generate a Back-end in MinutesSenchaCon 2016 - How to Auto Generate a Back-end in Minutes
SenchaCon 2016 - How to Auto Generate a Back-end in Minutes
Malin Weiss
ย 
I3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit Chopra
I3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit ChopraI3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit Chopra
I3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit Chopra
SPS Paris
ย 
RavenDB Presentation
RavenDB PresentationRavenDB Presentation
RavenDB Presentation
Mark Rodseth
ย 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
ย 
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
O365Con19 - Sharing Code Efficiently in your Organisation - Elio StruyfO365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
NCCOMMS
ย 
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL DatabasesDropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Kyle Banerjee
ย 
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Josh Carlisle
ย 
Porting ASP.NET applications to Windows Azure
Porting ASP.NET applications to Windows AzurePorting ASP.NET applications to Windows Azure
Porting ASP.NET applications to Windows Azure
Gunnar Peipman
ย 
Stack Exchange Infrastructure - LISA 14
Stack Exchange Infrastructure - LISA 14Stack Exchange Infrastructure - LISA 14
Stack Exchange Infrastructure - LISA 14
GABeech
ย 
A (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetITA (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetIT
Frank van der Linden
ย 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
Reuven Lerner
ย 
Postgres Open
Postgres OpenPostgres Open
Postgres Open
Ines Sombra
ย 
MongoDB at community engine
MongoDB at community engineMongoDB at community engine
MongoDB at community engine
mathraq
ย 
Why Wordnik went non-relational
Why Wordnik went non-relationalWhy Wordnik went non-relational
Why Wordnik went non-relational
Tony Tam
ย 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDB
Andrew Siemer
ย 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
indiver
ย 
Document Databases & RavenDB
Document Databases & RavenDBDocument Databases & RavenDB
Document Databases & RavenDB
Brian Ritchie
ย 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014
Ike Ellis
ย 
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
NCCOMMS
ย 
SenchaCon 2016 - How to Auto Generate a Back-end in Minutes
SenchaCon 2016 - How to Auto Generate a Back-end in MinutesSenchaCon 2016 - How to Auto Generate a Back-end in Minutes
SenchaCon 2016 - How to Auto Generate a Back-end in Minutes
Malin Weiss
ย 
I3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit Chopra
I3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit ChopraI3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit Chopra
I3 - Running SharePoint 2016 in Azure the do's and dont's - Jasjit Chopra
SPS Paris
ย 
RavenDB Presentation
RavenDB PresentationRavenDB Presentation
RavenDB Presentation
Mark Rodseth
ย 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
ย 
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
O365Con19 - Sharing Code Efficiently in your Organisation - Elio StruyfO365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
NCCOMMS
ย 
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL DatabasesDropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Kyle Banerjee
ย 
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Josh Carlisle
ย 
Porting ASP.NET applications to Windows Azure
Porting ASP.NET applications to Windows AzurePorting ASP.NET applications to Windows Azure
Porting ASP.NET applications to Windows Azure
Gunnar Peipman
ย 
Stack Exchange Infrastructure - LISA 14
Stack Exchange Infrastructure - LISA 14Stack Exchange Infrastructure - LISA 14
Stack Exchange Infrastructure - LISA 14
GABeech
ย 
A (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetITA (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetIT
Frank van der Linden
ย 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
Reuven Lerner
ย 
Postgres Open
Postgres OpenPostgres Open
Postgres Open
Ines Sombra
ย 

Similar to Lessons from the Trenches - Building Enterprise Applications with RavenDB (20)

Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
HostedbyConfluent
ย 
SQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The MoveSQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The Move
IBM Cloud Data Services
ย 
Learning to run
Learning to runLearning to run
Learning to run
dominion
ย 
QuerySurge for DevOps
QuerySurge for DevOpsQuerySurge for DevOps
QuerySurge for DevOps
RTTS
ย 
Azure cosmosdb
Azure cosmosdbAzure cosmosdb
Azure cosmosdb
Udaiappa Ramachandran
ย 
Linq
LinqLinq
Linq
Easy Communication & Technology
ย 
Bluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จ
Bluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จBluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จ
Bluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จ
uEngine Solutions
ย 
Bringing DevOps to the Database
Bringing DevOps to the DatabaseBringing DevOps to the Database
Bringing DevOps to the Database
Michaela Murray
ย 
Taming the shrew Power BI
Taming the shrew Power BITaming the shrew Power BI
Taming the shrew Power BI
Kellyn Pot'Vin-Gorman
ย 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
Andrew Siemer
ย 
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data LakeNDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
Tom Kerkhove
ย 
MSFT Dumaguete 061616 - Building High Performance Apps
MSFT Dumaguete 061616 - Building High Performance AppsMSFT Dumaguete 061616 - Building High Performance Apps
MSFT Dumaguete 061616 - Building High Performance Apps
Marc Obaldo
ย 
Document db
Document dbDocument db
Document db
Christian Holm Diget
ย 
Migrating on premises workload to azure sql database
Migrating on premises workload to azure sql databaseMigrating on premises workload to azure sql database
Migrating on premises workload to azure sql database
PARIKSHIT SAVJANI
ย 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
ย 
QuerySurge Slide Deck for Big Data Testing Webinar
QuerySurge Slide Deck for Big Data Testing WebinarQuerySurge Slide Deck for Big Data Testing Webinar
QuerySurge Slide Deck for Big Data Testing Webinar
RTTS
ย 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
Reinvently
ย 
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Otรกvio Santana
ย 
All daydevops 2016 - Turning Human Capital into High Performance Organizati...
All daydevops   2016 - Turning Human Capital into High Performance Organizati...All daydevops   2016 - Turning Human Capital into High Performance Organizati...
All daydevops 2016 - Turning Human Capital into High Performance Organizati...
John Willis
ย 
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf
ย 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
HostedbyConfluent
ย 
SQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The MoveSQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The Move
IBM Cloud Data Services
ย 
Learning to run
Learning to runLearning to run
Learning to run
dominion
ย 
QuerySurge for DevOps
QuerySurge for DevOpsQuerySurge for DevOps
QuerySurge for DevOps
RTTS
ย 
Bluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จ
Bluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จBluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จ
Bluemix paas แ„€แ…ตแ„‡แ…กแ†ซ saas แ„€แ…ขแ„‡แ…กแ†ฏ แ„‰แ…กแ„…แ…จ
uEngine Solutions
ย 
Bringing DevOps to the Database
Bringing DevOps to the DatabaseBringing DevOps to the Database
Bringing DevOps to the Database
Michaela Murray
ย 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
Andrew Siemer
ย 
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data LakeNDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
Tom Kerkhove
ย 
MSFT Dumaguete 061616 - Building High Performance Apps
MSFT Dumaguete 061616 - Building High Performance AppsMSFT Dumaguete 061616 - Building High Performance Apps
MSFT Dumaguete 061616 - Building High Performance Apps
Marc Obaldo
ย 
Migrating on premises workload to azure sql database
Migrating on premises workload to azure sql databaseMigrating on premises workload to azure sql database
Migrating on premises workload to azure sql database
PARIKSHIT SAVJANI
ย 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
ย 
QuerySurge Slide Deck for Big Data Testing Webinar
QuerySurge Slide Deck for Big Data Testing WebinarQuerySurge Slide Deck for Big Data Testing Webinar
QuerySurge Slide Deck for Big Data Testing Webinar
RTTS
ย 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
Reinvently
ย 
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Otรกvio Santana
ย 
All daydevops 2016 - Turning Human Capital into High Performance Organizati...
All daydevops   2016 - Turning Human Capital into High Performance Organizati...All daydevops   2016 - Turning Human Capital into High Performance Organizati...
All daydevops 2016 - Turning Human Capital into High Performance Organizati...
John Willis
ย 
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf
ย 
Ad

More from Oren Eini (6)

Staying friendly with the gc
Staying friendly with the gcStaying friendly with the gc
Staying friendly with the gc
Oren Eini
ย 
Rebooting design in RavenDB
Rebooting design in RavenDBRebooting design in RavenDB
Rebooting design in RavenDB
Oren Eini
ย 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
ย 
Should I use a document database?
Should I use a document database?Should I use a document database?
Should I use a document database?
Oren Eini
ย 
Delving into Documents with Data Subscriptions
Delving into Documents with Data SubscriptionsDelving into Documents with Data Subscriptions
Delving into Documents with Data Subscriptions
Oren Eini
ย 
RavenDB for modern web apps
RavenDB for modern web appsRavenDB for modern web apps
RavenDB for modern web apps
Oren Eini
ย 
Staying friendly with the gc
Staying friendly with the gcStaying friendly with the gc
Staying friendly with the gc
Oren Eini
ย 
Rebooting design in RavenDB
Rebooting design in RavenDBRebooting design in RavenDB
Rebooting design in RavenDB
Oren Eini
ย 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
ย 
Should I use a document database?
Should I use a document database?Should I use a document database?
Should I use a document database?
Oren Eini
ย 
Delving into Documents with Data Subscriptions
Delving into Documents with Data SubscriptionsDelving into Documents with Data Subscriptions
Delving into Documents with Data Subscriptions
Oren Eini
ย 
RavenDB for modern web apps
RavenDB for modern web appsRavenDB for modern web apps
RavenDB for modern web apps
Oren Eini
ย 
Ad

Recently uploaded (20)

Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
ย 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
ย 
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
ย 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
ย 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
ย 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
ย 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
ย 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
ย 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
ย 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
ย 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
ย 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
ย 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
ย 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
ย 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
ย 
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
ย 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
ย 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
ย 
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
ย 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
ย 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
ย 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
ย 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
ย 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
ย 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
ย 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
ย 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
ย 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
ย 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
ย 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
ย 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
ย 
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
ย 

Lessons from the Trenches - Building Enterprise Applications with RavenDB

  • 1. Lessons from theTrenches Dan Bishop RavenHQ [email protected] github.com/bishbulb twitter.com/bishbulb
  • 2. Typical Project Lifecycle Technical Discovery Convince Stakeholders Prototype Iterate Launch MVP Iterate Life is good! Life is good, right?
  • 3. Reality Sets In โ€ข Business is not โ€œfinishedโ€ with the MVP solution โ€ข Users are never satisfied โ€ข User hacks are conceived and proliferated โ€ข Small gaps grow into chasms โ€ข Production support issues start coming in โ€ข Things arenโ€™t shiny anymore
  • 4. Data Conversions โ€ข Properties are added and removed โ€ข Data types change โ€ข Class names and namespaces change โ€ข Documents are split or merged โ€ข Indexes change
  • 5. Data Conversions โ€“ Adding Properties public class OrderDelivery { public string Id { get; set; } public string Address { get; set; } public DateTime DeliveryDate { get; set; } } { "Address": "100 First St, NY, NY", "DeliveryDate": "2016-05-30T12:30:00" } public class OrderDelivery { public string Id { get; set; } public string Address { get; set; } public DateTime DeliveryDate { get; set; } public bool Expedited { get; set; } }
  • 6. Data Conversions โ€“ Adding Properties public class OrderDeliveriesIndex : AbstractIndexCreationTask<OrderDelivery> { public OrderDeliveriesIndex() { Map = docs => from doc in docs select new { doc.Address, doc.DeliveryDate, doc.Expedited }; } }
  • 7. Data Conversions โ€“ Adding Properties var expeditedDeliveries = session .Query<OrderDelivery, OrderDeliveriesIndex>() .Where(x => x.Expedited); if (expeditedDeliveries.Count > 10) { // email delivery manager }
  • 8. Javascript Patching var result = documentStore.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag: OrderDeliveries" }, new ScriptedPatchRequest { Script = "this.Expedited = true;" }, new BulkOperationOptions { AllowStale = false }); result.WaitForCompletion();
  • 9. Javascript Patching var result = documentStore.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag: OrderDeliveries" }, new ScriptedPatchRequest { Script = @" var customerLookup = JSON.parse('customers'); this.Expedited = customerLookup[this.CustomerId].IsPreferred;", Values = new Dictionary<string, object> { { "customers", JsonConvert.SerializeObject(customers) } } }); result.WaitForCompletion();
  • 10. Javascript Patching โ€ข Patch scripts always run against an index โ€ข Make patch scripts idempotent โ€ข Consider rollback strategy โ€ข Split changes into multiple releases โ€ข Debugging โ€ข Test in the Studio, use output() function โ€ข View patch progress in RavenDB 3.5
  • 11. Data Conversions โ€“ Removing Properties โ€ข Safe by default โ€ข Properties in the underlying document are retained documentStore.Conventions.PreserveDocumentPropertiesNotFoundOnModel = true; โ€ข Clutter by default โ€ข Keep track of the properties being removed โ€ข Run Javascript patch scripts in the next release to remove the properties
  • 12. You Want All the Data? โ€ข Raven intentionally makes this hard with the normal APIs โ€ข Indexes can be stale, query results limited to 1024 results โ€ข Streaming to the rescue var results = session.Advanced.Stream<OrderDelivery>("orderdeliveries-"); session.Advanced.LoadStartingWith<OrderDelivery>("orderdeliveries-", start: 0, pageSize: 1000); var query = session.Query<OrderDelivery, OrderDeliveriesIndex>() .Where(x => !x.Delivered); var results = session.Advanced.Stream(query); โ€ข Other tips session.Advanced.MaxNumberOfRequestsPerSession = int.MaxValue;
  • 13. Semantic Document Identifiers โ€ข Identifiers that have embedded data/context โ€ข employees/1/deliveryroutes/2016-06-01 โ€ข Prevents logical duplicates โ€ข Enables multi-load with one round-trip โ€ข employees/1/preferences โ€ข employees/1/workschedule โ€ข deliveryroutes/2016-06-01/employees/1 โ€ข Enables you to bypass indexes altogether โ€ข Example: Get all delivery routes for a particular day
  • 14. LoadDocument Manager Employee1 Employee2 EmployeeN public EmployeesIndex() { Map = employeees => from employee in employeees let manager = LoadDocument<Manager>(employee.ManagerId) select new { employee.Id, ManagerName = manager.Name }; }
  • 15. LoadDocument Manager CompanyVehicle public CompanyVehiclesIndex() { Map = vehicles => from vehicle in vehicles let manager = LoadDocument<Manager>(vehicle.ManagerId) select new { vehicle.Id, ManagerName = manager.Name }; }
  • 16. LoadDocument โ€ข One to many relationships could cause problems โ€ข Only when updating the document that has many other documents referencing it โ€ข One to one relationships are fine โ€ข Look for alternatives โ€ข Transformers โ€ข Data duplication
  • 17. Auto vs Static Indexes โ€ข Auto indexes are great for prototyping โ€ข Consider the implications <appSettings> <add key="Raven/CreateAutoIndexesForAdHocQueriesIfNeeded" value="false" /> </appSettings> โ€ข Indexes are resource intensive โ€ข Be aware of the indexes you have
  • 18. WaitForNonStaleResults โ€ข Gives you up-to-date results from an index โ€ข Dealing with CRUD views โ€ข Make the writer wait for indexes, not the reader var results = session .Query<OrderDelivery, OrderDeliveriesIndex>() .Customize(x => x.WaitForNonStaleResultsAsOfNow());
  • 19. Consistency Issues โ€ข ACID provides specific guarantees โ€ข DistributedTransactions โ€ข DTC commit and rollback happen in a separate thread from updates โ€ข Rather than locking the underlying documents, Raven will allow you to access them but will return an HTTP 203 Non-Authoritative response โ€ข Scenario: NServiceBus processing chain of messages UpdateUserProfile ConfirmPhoneNumber session.Advanced.AllowNonAuthoritativeInformation = false;
  • 20. Replication Failover Create Order Upgrade to Expedited Delivery Schedule Delivery Failover to secondary node โ€ข Consider multi-transaction business workflows โ€ข What happens if the Raven client fails over to another node midway through the processing sequence?
  • 21. Replication Failover โ€ข Consider the risk/reward of allowing automatic failover โ€ข Manual failover is an option โ€ข Secondary nodes are treated as โ€œhot standbyโ€ nodes โ€ข Mix-and-match failover behaviors โ€ข Consider SLAs and business needs when deciding on failover strategies โ€ข These tradeoffs are not specific to RavenDB โ€ข All distributed systems have similar challenges