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

Relational vs. Document DBs - How do I decide?

Relational vs. Document DBs - How do I decide?

This presentation will recap the design considerations developers prioritize in picking one technology over the other. Using SQL Server and MongoDB as representative systems, we will consider the developer experience using these technologies. We will take a look at at the tools used to design, query, transform and optimize both relational and document database systems. Finally, we will take a brief look at Cosmos and the features it offers extending and simplifying the cognitive load a little bit more than Mongo.

This presentation is aimed at the developers who have been using either relational or document database technology and want to see what they were missing.

Doug Corbett

November 28, 2017
Tweet

More Decks by Doug Corbett

Other Decks in Programming

Transcript

  1. Agenda A Little About Me Recap of Relational Database Features

    Anatomy of a Claim Possible Claim Models
  2. Agenda A Little About Me Recap of Relational Database Features

    Anatomy of a Claim Document Database Features Claims Document CosmosDB Possible Claim Models
  3. Agenda A Little About Me Recap of Relational Database Features

    Anatomy of a Claim Insights and Opinions Document Database Features Claims Document CosmosDB Possible Claim Models x
  4. A Little About Me – The Early Days • http://techland.time.com/2012/08/03/trs-80/

    http://www.advanceddungeonsandparenting.com/2017/08/tom-moldvay-basic-why-its-great-and.html
  5. A Little About Me – The Early Days 5th Grade

    Dungeon & Dragons Character Generator • http://techland.time.com/2012/08/03/trs-80/ http://www.advanceddungeonsandparenting.com/2017/08/tom-moldvay-basic-why-its-great-and.html
  6. A Little About Me – Dose of Reality • https://en.wikipedia.org/wiki/Pong

    • https://www.rottentomatoes.com/m/shrek_forever_after/
  7. Things I Care About • Low cost of ownership •

    Bulletproof code • Maintainable Code (Clean Code and SOLID principle) • Leverage code generation • Reduce code needed to accomplish the goal x
  8. Purpose of a Database? To allow data to be saved

    and retrieved in a reliable and performant manner.
  9. What is a Relational Database? A collection of data items

    organized as a set of formally-described tables from which data can be accessed or reassembled in many different ways without having to reorganize the database tables. Application agnostic design
  10. Normal Forms 1nf – one value per field 2nf –

    All the non-key columns in a table depend directly or indirectly on the primary key. 3nf – columns depend directly key columns only • https://en.wikipedia.org/wiki/ACID
  11. “ACID” Transactions Atomic – all or nothing Consistent – completed

    transaction result in a valid state Isolated – transactions do not interfere with each other except to roll them back Durability – once a transaction completes, it will remain in effect even after a power loss. • https://en.wikipedia.org/wiki/ACID
  12. Security Authorization • Server level • Database level • Schema

    level • Object level Authentication • Windows • SQL Server • Mixed Roles • Server • Database • Application
  13. Logical and Physical Architecture SQL Server SQL Server Clients Replication

    Cluster Write actions Read actions Clients Publish x
  14. Simple query Two table query Sub queries – Get claims

    with Attending physician “Rick Martins” Duplicate problem - have to decide what to do with duplicates Getting all data – lots of queries Example Queries
  15. Get claim with ID 12 – 2 ms per head

    record Save a claim – have to handle each child explicitly Example Usage in C# x
  16. What is a Document Database? A system for storing semi

    structured data, usually in the form of JSON. Advantages include being able to design data models that support common data access patterns and being able to access relevant data with a single query. Specifically, MongoDB does not support joins and multi table transactions. This allows scaling out on commodity hardware by design. Developers can design their applications without being concerned about deployment details. * https://university.mongodb.com/
  17. What is a Document Database? Scalability & Performance Functionality Key/value

    stores RDBMS MongoDB * https://university.mongodb.com/
  18. Aggregation Framework Mongo’s answer to SQL’s Group By Clause and

    Aggregation functions. $project $match $group $sort Collection Result Aggregation Pipeline $skip $limit $unwind $out
  19. Logical Architecture - Shards Sharded Cluster A-M Sharded Cluster N-Z

    Mongo Routing Service (mongos) Node 3 Node 2 Primary Node Node 3 Node 2 Primary Node
  20. Security Authorization • Server level • Database level • Collection

    level Authentication • Trusted environment • MongoDB Authentication Roles • Server • Database • Collection • User Defined subnet Web Server Mongo
  21. Simple query Two table query Sub queries – Get claims

    with Attending physician “Rick Martins” Duplicate problem - have to decide what to do with duplicates Getting all data – lots of queries Example Queries
  22. Get claim with ID 12 – 2 ms per head

    record Save a claim – have to handle each child explicitly Example Usage in C# x
  23. • Easy to refactor • Performant • Horizontal scalability by

    design • Reduced complexity • No DBA required (sort of) • No need for Object Relationship Mappers (ORM) • Data is more readable • Less code • Free, sort of Benefits of MongoDB over SQL Server
  24. • Learning takes time - start small to gain experience

    • Might still need someone to focus on infrastructure Lessons Learned using MongoDB
  25. • Learning takes time - start small to gain experience

    • Might still need someone to focus on infrastructure • Need to think through data validation Lessons Learned using MongoDB
  26. • Learning takes time - start small to gain experience

    • Might still need someone to focus on infrastructure • Need to think through data validation • MongoDB can be used in Lieu of most RDBMS data stores Lessons Learned using MongoDB
  27. • Learning takes time - start small to gain experience

    • Might still need someone to focus on infrastructure • Need to think through data validation • MongoDB can be used in Lieu of most RDBMS data stores • Replacing is expensive and risky. Lessons Learned using MongoDB
  28. • Learning takes time - start small to gain experience

    • Might still need someone to focus on infrastructure • Need to think through data validation • MongoDB can be used in Lieu of most RDBMS data stores • Replacing is expensive and risky. • Semi-technical people may need to learn a new way of querying Lessons Learned using MongoDB
  29. When would I prefer a RDBMS over a document database?

    • Brown-field apps that are fast enough
  30. When would I prefer a RDBMS over a document database?

    • Brown-field apps that are fast enough • Financial apps that require ACID transactions
  31. When would I prefer a RDBMS over a document database?

    • Brown-field apps that are fast enough • Financial apps that require ACID transactions • Ad Hoc Reporting databases
  32. When would I prefer a document database over a RDBMS?

    • Brown-field apps that need to scale better
  33. When would I prefer a document database over a RDBMS?

    • Brown-field apps that need to scale better • All green-field apps x
  34. How to Evolve from RDBMS to NoSQL + SQL https://mapr.com/blog/how-evolve-rdbms-nosql-sql/

    Mongo University https://university.mongodb.com/ SQL to Mongo Comparison https://docs.mongodb.com/manual/reference/sql-comparison/ BSON Specification http://bsonspec.org/ Aggregation Pipeline https://docs.mongodb.com/manual/aggregation/ https://docs.mongodb.com/manual/tutorial/aggregation-zip-code-data-set/ Azure Cosmos DB https://azure.microsoft.com/en-us/services/cosmos-db/?v=17.45b “UB-04 Handbook For Hospital Billing” (book) – Author Claudia Birkenshaw, M.S.A Claim Demo App https://github.com/dougcorbett/ClaimsDemo Reference Materials