30
ww.aditi.com AZURE DOCUMENT DB G SARAVANAN www.aditi.c om

AzureDocumentDB

Embed Size (px)

Citation preview

Page 1: AzureDocumentDB

ww.aditi.com

AZURE DOCUMENT DB

G SARAVANAN

www.aditi.com

Page 2: AzureDocumentDB

ww.aditi.com

Orchestrated by…

www.aditi.com

Page 3: AzureDocumentDB

ww.aditi.com

Azure Document DB?• NoSQL document database service designed for modern mobile and web

applications• Provides fast read and write• Easily scale up and down on demand• JavaScript integration• Schema less database• Enables complex ad hoc queries using SQL language• Multi-Document transaction processing using Stored Procedure, triggers &

UDFs• Natively supports JSON documents

3

Page 4: AzureDocumentDB

ww.aditi.com

Where does it fits?

4

Page 5: AzureDocumentDB

ww.aditi.com

Resource Model

5

Page 6: AzureDocumentDB

ww.aditi.com

Resource DescriptionDatabase account A database account is associated with a set of databases and a fixed amount of blob storage for attachments (preview

feature). You can create one or more database accounts using your Azure subscription. Every Standard database account is allocated a minimum capacity of one S1 collection. For more information, visit our pricing page.

Database A database is a logical container of document storage partitioned across collections. It is also a users container.User The logical namespace for scoping/partitioning permissions.Permission An authorization token associated with a user for authorized access to a specific resource.Collection A collection is a container of JSON documents and the associated JavaScript application logic. A collection is a billable

entity, where the cost is determined by the performance level associated with the collection. The performance levels (S1, S2 and S3) provide 10GB of storage and a fixed amount of throughput. For more information on performance levels, visit our performance page.

Stored Procedure Application logic written in JavaScript which is registered with a collection and transactionally executed within the database engine.

Trigger Application logic written in JavaScript modeling side effects associated with insert, replace or delete operations.UDF A side effect free, application logic written in JavaScript. UDFs enable you to model a custom query operator and thereby

extend the core DocumentDB query language.Document User defined (arbitrary) JSON content. By default, no schema needs to be defined nor do secondary indices need to be

provided for all the documents added to a collection.Attachment An attachment is a special document containing references and associated metadata for external blob/media. The

developer can choose to have the blob managed by DocumentDB or store it with an external blob service provider such as OneDrive, Dropbox, etc.

Page 7: AzureDocumentDB

ww.aditi.com

Addressing a resourceValue of the _self Description

/dbs Feed of databases under a database account.

/dbs/{_rid-db} Database with the unique id property with the value {_rid-db}.

/dbs/{_rid-db}/colls/ Feed of collections under a database.

/dbs/{_rid-db}/colls/{_rid-coll} Collection with the unique id property with the value {_rid-coll}.

/dbs/{_rid-db}/users/ Feed of users under a database.

/dbs/{_rid-db}/users/{_rid-user} User with the unique id property with the value {_rid-user}.

/dbs/{_rid-db}/users/{_rid-user}/permissions Feed of permissions under a database.

/dbs/{_rid-db}/users/{_rid-user}/permissions/{_rid-permission} Permission with the unique id property with the value {_rid-permission}.

7

Page 8: AzureDocumentDB

ww.aditi.com

Document DB logical view

8

Page 9: AzureDocumentDB

ww.aditi.com

Relational View – Document Data View

9

Page 10: AzureDocumentDB

ww.aditi.com

Modeling Data in Document DB• Embedding data

10

When to embedIn general, use embedded data models when:• There are contains relationships between entities.• There are one-to-few relationships between entities.• There is embedded data that changes infrequently.• There is embedded data won't grow without bound.

Page 11: AzureDocumentDB

ww.aditi.com

• Referencing data

11

When to referenceIn general, use normalized data models when:• Representing one-to-many relationships.• Representing many-to-many relationships.• Related data changes frequently.• Referenced data could be unbounded.

Page 12: AzureDocumentDB

ww.aditi.com

• Hybrid data (Combination of embed & referencing)

12

Detail Info: https://azure.microsoft.com/en-in/documentation/articles/documentdb-modeling-data/

Page 13: AzureDocumentDB

ww.aditi.com

Indexing

13

• Specified at the collection level• Automatic indexing

– By default, all documents are automatically indexed, but you can choose to turn it off.

– When indexing is turned off, documents can be accessed only through their self-links or by queries using ID.

Page 14: AzureDocumentDB

ww.aditi.com 14

• Indexing mode– Consistent – By default indexes synchronously updated on insert, replace or delete– Lazy – asynchronous index update (targeted at bulk ingestion)

Page 15: AzureDocumentDB

ww.aditi.com 15

• Indexing Types Hash – supports efficient equality and JOIN queries Range – supports efficient equality queries, range queries (using >, <, >=, <=, !=), and Order By queries Hash:SELECT * FROM collection c WHERE c.prop = "valueSELECT tag FROM collection c JOIN tag IN c.props WHERE tag = 5

Range:SELECT * FROM collection c WHERE c.prop = "value“SELECT * FROM collection c WHERE c.prop > 5SELECT * FROM collection c ORDER BY c.prop

Note: Range indexes are supported only for numeric values.

Page 16: AzureDocumentDB

ww.aditi.com

Indexing logical View

16

Example:JSON property: {"headquarters": "Belgium"} Corresponds to the path: /"headquarters"/"Belgium". JSON array: {"exports": [{"city": “Moscow"}, {"city": Athens"}]} Correspond to the paths: /"exports"/0/"city"/"Moscow" and /"exports"/1/"city"/"Athens".

Page 17: AzureDocumentDB

ww.aditi.com

Consistency levels The choice of consistency level has performance implications for both write and read operations. It applies to all the collections in the database (future there is a plan of overriding the consistency level per collection basics)• Strong

– provides absolute guarantees on data consistency, but offers the lowest level of read and write performance. • Bounded staleness

– provides more predictable behavior for read consistency while offering the lowest latency writes• Session

– provides predictable read data consistency for a session while offering the lowest latency writes• Eventual

– provides the weakest read consistency but offers the lowest latency for both reads and writes.

17

Page 18: AzureDocumentDB

ww.aditi.com

Securing access • Account administrator

– Full access to all of the resources (administrative and application) within a given DocumentDB account.• Read-only administrator

– Read-only access to all of the resources (administrative and application within a given DocumentDB account. • Database user:

– The DocumentDB user resource associated with a specific set of DocumentDB database resources (e.g. collections, documents, scripts).

18

Administrative resources • Account• Database• User• Permission

Application resources • Collection• Document• Attachment• Stored procedure• Trigger• User-defined function

Page 19: AzureDocumentDB

ww.aditi.com

Create User & Permission

19

Page 20: AzureDocumentDB

ww.aditi.com

Stored Procedure

20

Creating, registering and executing the sample hello world stored procedure

Page 21: AzureDocumentDB

ww.aditi.com

Triggers (Pre – Trigger)

21

Validating the properties of a document that is being created

Page 22: AzureDocumentDB

ww.aditi.com

UDF’s

22

Creates a UDF to calculate income tax based on rates for various income brackets, and then uses it inside a query to find all people who paid more than $20,000 in taxes.

Page 23: AzureDocumentDB

ww.aditi.com

DocumentDB Queries

23

http://www.documentdb.com/sql/demo

Page 24: AzureDocumentDB

ww.aditi.com

Pricing

24

Page 25: AzureDocumentDB

ww.aditi.com

Libraries

25

• .NET API• Node.js• Java• JavaScript• Python

Page 26: AzureDocumentDB

ww.aditi.com

Limits and quotas

26

ENTITY QUOTA (STANDARD OFFER)

Database Accounts* 5

Number of databases per database account 100

Number of users per database account – across all databases 500,000

Number of permissions per database account – across all databases

2,000,000

Attachment storage per database account (Preview Feature) 2 GB

Maximum Request Units / second per collection 2500

Number of stored procedures, triggers and UDFs per collection* 25 each

Maximum execution time for stored procedure and trigger 5 seconds

Provisioned document storage / collection 10 GB

Maximum collections per database account* 100

Maximum document storage per database (100 collections)* 1 TB

Maximum Length of the Id property 255 characters

Maximum items per page 1000

Page 27: AzureDocumentDB

ww.aditi.com 27

ENTITY QUOTA (STANDARD OFFER)

Maximum request size of document and attachment 512KB

Maximum request size of stored procedure, trigger and UDF

512KB

Maximum response size 1MB

String All strings must conform to the UTF-8 encoding. Since UTF-8 is a variable width

encoding, string sizes are determined using the UTF-8 bytes.

Maximum length of property or value No practical limit

Maximum number of UDFs per query* 1

Maximum number of built-in functions per query No practical limit

Maximum number of JOINs per query* 2

Maximum number of AND clauses per query* 5

Maximum number of OR clauses per query* 5

Maximum number of values per IN expression* 100

Maximum number of collection creates per minute* 5

Maximum number of scale operations per minute* 5

Page 28: AzureDocumentDB

ww.aditi.com

Demo

28

Page 29: AzureDocumentDB

ww.aditi.com

It’s time for QUESTIONS & ANSWERS

Your FEEDBACK is valuable

Join us AGAIN for more tech talks

THANK YOU

www.aditi.com