Introduction to Azure DocumentDB Jeff Renz, BI Architect RevGen Partners
Thank You Presenting Sponsors Gain insights through familiar tools while balancing monitoring and managing user created content across structured and unstructured sources. Unifying computer, storage, networking, and virtualization, Cisco UCS is the optimal database and business intelligence platform for SQL Server. Supporting Sponsors Solutions from Dell help you monitor, manage, protect and improve your SQL Server environment. www.microsoft.com www.cisco.com www.software.dell.com 2 2
Planning on attending PASS Summit 2015? Start saving today! The world s largest gathering of SQL Server & BI professionals Take your SQL Server skills to the next level by learning from the world s SQL Server experts, in over 190 technical sessions Over 5000 attendees, representing 2000 companies, from 52 countries, ready to network & learn Contact your Local or Virtual Chapter for an additional $150 discount. $1795 until July 12 th, 2015
Jeff Renz BI Architect at RevGen Partners 15 years SQL Server and BI 10 years Data Warehouse Design and Implementation jrenz@revgen.com jeff.renz @jeff_renz jeff-renz 4
Agenda Getting Going With Azure DocumentDB Creating and Working with JSON Azure DocumentDB Overview JSON Validation 5 5
Microsoft Azure DocumentDB 6 6
Azure DocumentDB DocumentDB delivers consistently fast reads and writes, schema flexibility and the ability to easily scale a database up and down on demand Microsoft Azure DocumentDB is a NoSQL document database service designed for modern mobile and web applications 7 7
Getting To Azure https://portal.azure.com/ 8 8
Create a New DocumentDB In Azure 9 9
Quick Start 10 10
Demo Provision a DocumentDB
Azure DocumentDB Azure DocumentDB natively supports JSON documents enabling easy iteration of application schema It embraces the ubiquity of JSON and JavaScript, eliminating mismatch between the application type system and database schema Deep integration of JavaScript also allows developers to execute application logic efficiently directly within the database engine within a database transaction 12 12
What is JSON? JSON (JavaScript Object Notation) is a lightweight data-interchange format It is easy for humans to read and write It is easy for machines to parse and generate It is based on a subset of the JavaScript Programming Language JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages These properties make JSON an ideal data-interchange language 13 13
JSON - Object An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by, (comma). 14 14
JSON - Array An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by, (comma). 15 15
JSON - Value A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested. 16 16
JSON - Number A number is very much like a C or Java number, except that the octal and hexadecimal formats are not used. 17 17
What About XML? For awhile, XML (extensible markup language) was the only choice for open data interchange. But over the years there has been a lot of transformation in the world of open data sharing. The more lightweight JSON has become a popular alternative to XML for various reasons XML <root EmployeeName="Arnie Admin"> <Role> <item> <RoleID>1</RoleID> <RoleName>"Developer"</RoleName> </item> <item> <RoleID>2</RoleID> <RoleName>"DBA"</RoleName> </item> </Role> </root> JSON { "EmployeeName": "Arnie Admin", "Role": [ { "RoleID":1, "RoleName": "Developer" }, { "RoleID":2, "RoleName": "DBA" }] } 18 18
Why JSON is Better Than XML Less verbose- XML uses more words than necessary JSON is faster- Parsing XML software is slow and cumbersome. Applications can use large amounts of memory due to the verbosity and cost of parsing large XML files Benchmark two million row of business data Text Gzip Zip Duration XML 91.78M 18.74M 3.38s JSON 49.78M 17.09M 2.78s XML Overhead 84.38% 9.62% 21.3% http://www.codeproject.com/articles/604720/json-vs-xml-some-hard-numbers-about-verbosity 19 19
JSON Use Case Project Details Create commission Engine and modeling tool Scenario Modeling includes changing payout ranges and rates based upon performance metrics Modeling includes setting goals/targets for commissions paid sales agents, supervisors and managers Complex rate card had over 1296 payouts Benefits JSON avoids serialization development (mapping data from SQL to C# objects) Scenario creation passes a high amount of parameters from UI to database Goal to have a reusable design for other implementations 20 20
Metric B Complex Rate Card Example Metric A 21 21
Consuming JSON Strings in SQL https://www.simple-talk.com/sql/t-sqlprogramming/consuming-json-strings-in-sql-server/ 22 22
Validating JSON Strings JSON Viewer for NotePad++ 23 23
Demo Creating and Working with JSON
Azure DocumentDB Modern Applications Produce, consume and respond quickly to very large volumes of data Evolve very rapidly and so does the underlying data schema. Developers have increasingly chosen schema-free NoSQL document databases as simple, fast, elastic solutions to store and process data Advantages Many schema-free databases do not allow non-trivial queries and transactional processing, making advanced data management hard. Microsoft developed Azure DocumentDB to provide these capabilities when managing schema-free data 25 25
Azure DocumentDB You can use Azure DocumentDB to store flexible datasets that require query retrieval and transactional processing 26 26
Azure DocumentDB Indexing Technology DocumentDB utilizes a highly concurrent, lock free, log structured indexing technology to automatically index all document content. This enables rich real-time queries without the need to specify schema hints, secondary indexes or views Fully Managed Eliminate the need to manage database and machine resources. As a fullymanaged Microsoft Azure service, you do not need to manage virtual machines, deploy and configure software, or deal with complex data-tier upgrades. Every database is automatically backed up and protected against regional failures 27 27
Azure DocumentDB Provision Provision Capacity 28 28
Azure DocumentDB Consistency Options Maintains at least three copies of all data, storing each copy on a different physical server Replicating each collection also helps reliability by ensuring that data is still available even if one or two servers become inaccessible Types Strong Bounded Staleness Session (Default) Eventual 29 29
Azure DocumentDB Consistency Strong A DocumentDB client always sees completely consistent data. The tradeoff is that reads and writes are slower than with the other three options. An application that must always see the most current data, such as banking software that moves money between documents, might choose this option Bounded A client might see old data, but it s guaranteed to see changes in the order in which they were made. In other words, clients will never see out-of-order data. A client can also specify a limit for how old that data can be, e.g., one second. In a multi-player game, for instance, which requires great performance and strict ordering of events, Bounded Staleness might be the right choice. 30 30
Azure DocumentDB Consistency Session (Default) A client will always read its own writes correctly, but other clients reading this same data might see older values or out-oforder updates. An application that works on behalf of a specific user, such as a blogging application, might choose this option. Eventual This option has the highest performance, but a client might sometimes read out-ofdate information or see updates out of order 31 31
Azure DocumentDB Resources 32 32
Azure DocumentDB Structure 33 33
Azure DocumentDB Structure 34 34
Azure DocumentDB Stored Procedures 35 35
Demo Azure DocumentDB
JSON Schema Validation JSON Schema Validation http://jsonschema.net/#/ Allow Additional Properties Force Required Restrict Values to Enum C# Validate JSON Against Schema http://www.netonsoft.com/json JSON.net Schema Create Unit Tests JSON from DB Create Unit Tests JSON to DB 37 37
Send JSON From DB to C# 38 38
Demo Schema Binding