+ All Categories
Home > Technology > Introduction to Azure DocumentDB

Introduction to Azure DocumentDB

Date post: 16-Apr-2017
Category:
Upload: alex-zyl
View: 108 times
Download: 0 times
Share this document with a friend
73
Transcript
Page 1: Introduction to Azure DocumentDB
Page 2: Introduction to Azure DocumentDB

Alexander Zyl.NET Developer

[email protected]

Page 3: Introduction to Azure DocumentDB

A new child

Page 4: Introduction to Azure DocumentDB

NoSQL solutions in Azure

HBase

TS

• Column Family Store • Key/Value Store

RedisTS

Page 5: Introduction to Azure DocumentDB

Features:

• Fully managed• Schema agnostic• Scalable• Tunable consistency levels• Tunable indexing policies• Familiar SQL syntax for querying• JavaScript execution

DocumentDB

Page 6: Introduction to Azure DocumentDB

DocumentDB resource model

REST API

DocumentDB Infrastructure

Page 7: Introduction to Azure DocumentDB

Databases/dbs/{id}

DocumentDB Account

Page 8: Introduction to Azure DocumentDB

Databases/dbs/{id}

DocumentDB Account

Page 9: Introduction to Azure DocumentDB

Collections/colls/{id}

Databases/dbs/{id}

Users/users/{id}

Permissions/permissions/{id}

Page 10: Introduction to Azure DocumentDB

Collections/colls/{id}

Databases/dbs/{id}

Users/users/{id}

Permissions/permissions/{id}

Page 11: Introduction to Azure DocumentDB

Triggers/triggers/{id}

Functions/functions/{id}

Stored Procedures/sprocs/{id}

Attachments/attachments/{id}

Documents/docs/{id}

Collections/colls/{id}

Page 12: Introduction to Azure DocumentDB

DocumentDB Account Users

/users/{id}Databases/dbs/{id}

Permissions/permissions/{id}

Collections/colls/{id}

Attachments/attachments/{id}

Documents/docs/{id}

Triggers/triggers/{id}

Functions/functions/{id}

Stored Procedures/sprocs/{id}

Page 13: Introduction to Azure DocumentDB

Server ZServer CServer BServer A

Logical containers

Physical containers

DocumentDB Account

CollectionsCollections Collections Collections

Page 14: Introduction to Azure DocumentDB

What about cost?

Page 15: Introduction to Azure DocumentDB

¿ 𝑓 (𝑀𝑒𝑚𝑜𝑟𝑦 ,𝐶𝑃𝑈 , 𝐼𝑂 )RURequest Unit

Page 16: Introduction to Azure DocumentDB

Performance levels

RUs per second RUs per second20 20 20 RUs per second RUs per second250 RUs per second 1k RUs per second 2.5k RUs per second

Page 17: Introduction to Azure DocumentDB

How to model data?

Page 18: Introduction to Azure DocumentDB

{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" }, "GPSLocation": { "Latitude": 44.6516185, "Longitude": -63.5820275 }, "StatusData": […]}

Vehicle Dealer

StatusData

VehicleIdPK PK

PK

ReleaseYear

Make

DealerId

Name

StatusId

VehicleIdEngineOnTimeStamp

Address

Vin

Model

LatitudeLongitude

Page 19: Introduction to Azure DocumentDB

Approaches to document modeling

Reference data Embed data

Page 20: Introduction to Azure DocumentDB

Modeling relations

Page 21: Introduction to Azure DocumentDB

Vehicle document:{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" }, "GPSLocation": { "Latitude": 44.6516185, "Longitude": -63.5820275 }, "StatusData": [ { "Id": 1, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 40 }, { "Id": 2, "TimeStamp": "2014-07-04", "EngineOn": false, "FuelLevel": 33 },

{ "Id": 999, "TimeStamp": "2014-08-12", "EngineOn": true, "FuelLevel": 23 } ]}

Bad design

Page 22: Introduction to Azure DocumentDB

When to embed: One-to-few relations Infrequent changes Embedded data has

bounds

Modeling relations

Page 23: Introduction to Azure DocumentDB

Vehicle document:{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" }, "GPSLocation": { "Latitude": 44.6516185, "Longitude": -63.5820275 }, "StatusData": [ { "Id": 1, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 40 }, { "Id": 2, "TimeStamp": "2014-07-04", "EngineOn": false, "FuelLevel": 33 },

{ "Id": 999, "TimeStamp": "2014-08-12", "EngineOn": true, "FuelLevel": 23 } ]}

Page 24: Introduction to Azure DocumentDB

When to embed: One-to-few relations Infrequent changes Embedded data has

bounds

When to reference: One-to-many relations Many-to-many relations Data changes frequently Unbounded reference

Modeling relations

Page 25: Introduction to Azure DocumentDB

Vehicle document:{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" }, "GPSLocation": { "Latitude": 44.6516185, "Longitude": -63.5820275 }, "StatusData": [ { "Id": 1, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 40 }, { "Id": 2, "TimeStamp": "2014-07-04", "EngineOn": false, "FuelLevel": 33 },

{ "Id": 999, "TimeStamp": "2014-08-12", "EngineOn": true, "FuelLevel": 23 } ]}

Vehicle document:

{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" }, "StatusData": [ { "Id": 1, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 40 }, { "Id": 2, "TimeStamp": "2014-07-04", "EngineOn": false, "FuelLevel": 33 }, { "Id": 3, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 23 },

{ "Id": 999, "TimeStamp": "2014-08-12", "EngineOn": true, "FuelLevel": 23 } ]}

VehicleLocation document:

{ "VehicleId": 44, "GPSLocation": { "Latitude": 44.651617, "Longitude": -63.582027 }}

Page 26: Introduction to Azure DocumentDB

Vehicle

{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" }, "StatusData"95,: [ { "Id": 1, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 40 }, { "Id": 2, "TimeStamp": "2014-07-04", "EngineOn": false, "FuelLevel": 33 }, { "Id": 3, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 23 },

{ "Id": 999, "TimeStamp": "2014-08-12", "EngineOn": true, "FuelLevel": 23 } ]}

Vehicle document:

{ "Id": 44, "ReleaseYear": "2014", "Make": "Aston Martin", "Vin": "2G1WT58KX79250102", "Model": "DBS", "Dealer": { "Name": "Atlant-M", "Address": "Some st. 9" },}VehicleStatus documents:{ "Id": 1, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 40, "VehicleId": 44 },{ "Id": 2, "TimeStamp": "2014-07-04", "EngineOn": false, "FuelLevel": 33, "VehicleId": 44 },{ "Id": 3, "TimeStamp": "2014-07-04", "EngineOn": true, "FuelLevel": 23, "VehicleId": 44 },{ "Id": 4, "TimeStamp": "2014-07-05", "EngineOn": true, "FuelLevel": 10, "VehicleId": 44 },{ "Id": 5, "TimeStamp": "2014-07-06", "EngineOn": false, "FuelLevel": 55, "VehicleId": 44 },{ "Id": 999, "TimeStamp": "2014-08-12", "EngineOn": true, "FuelLevel": 23, "VehicleId": 44 }

Page 27: Introduction to Azure DocumentDB

Indexing

Page 28: Introduction to Azure DocumentDB

Documents in a collection{ "id": 16, "text": "Bonjour", "user": { "name": "Francois", "nickname": "@franky" }, "entities": { "hashtags": [ { "text": "#heof" } ] }}

{ "id": 4, "text": "Hello", "user": { "name": "Jerome", "nickname": "@juim" }, "entities": { "hashtags": [ { "text": "#rutib", "indices": [ 10, 26 ] } ] }}

Page 29: Introduction to Azure DocumentDB

Index tree

textid userentities

4 16 Hello Bonjourname nickname

Jerome Francois @juim @franky

hashtags

text indices

0

10 26

0

#rutib #heof

Page 30: Introduction to Azure DocumentDB

What we can controlAutomatic indexing Manual include Manual exclude

Page 31: Introduction to Azure DocumentDB

What we can control

Automatic indexing Manual include Manual exclude

Page 32: Introduction to Azure DocumentDB

What we can control

Indexing modes Consistent Lazy None

Page 33: Introduction to Azure DocumentDB

What we can control

Indexing modes Consistent Lazy None

Page 34: Introduction to Azure DocumentDB

Building paths{ "id": 16, "text": "Bonjour", "user": { "name": "Francois", "nickname": "@franky" }, "entities": { "hashtags": [ { "text": "#heof" } ] }}

_.text _.user.name _.entities.hashtags _.entities.hashtags[0].text

Page 35: Introduction to Azure DocumentDB

Building paths

Applicable wildcards:? – single selection

/text/?/user/nickname/?/entities/hashtags/[]/text/?

Page 36: Introduction to Azure DocumentDB

{ "id": 4, "text": "Hello", "user": { "name": "Jerome", "nickname": "@juim" }, "entities": { "hashtags": [ { "text": "#rutib", "indices": [ 10, 26 ] } ] }}

/text/?

Building paths: examples

Page 37: Introduction to Azure DocumentDB

{ "id": 4, "text": "Hello", "user": { "name": "Jerome", "nickname": "@juim" }, "entities": { "hashtags": [ { "text": "#rutib", "indices": [ 10, 26 ] } ] }}

/user/nickname/?

Building paths: examples

Page 38: Introduction to Azure DocumentDB

Building paths

Applicable wildcards:? – single selection* – recursive selection/text/?

/user/nickname/?/entities/hashtags/[]/text/?

/user/*/entities/*/entities/hashtags/[]/*

Page 39: Introduction to Azure DocumentDB

{ "id": 4, "text": "Hello", "user": { "name": "Jerome", "nickname": "@juim" }, "entities": { "hashtags": [ { "text": "#rutib", "indices": [ 10, 26 ] } ] }}

/user/*

Building paths: examples

Page 40: Introduction to Azure DocumentDB

{ "id": 4, "text": "Hello", "user": { "name": "Jerome", "nickname": "@juim" }, "entities": { "hashtags": [ { "text": "#rutib", "indices": [ 10, 26 ] } ] }}

/entities/hashtags/*

Building paths: examples

Page 41: Introduction to Azure DocumentDB

Indexing options:Include to index Exclude from index

Applying rules

Page 42: Introduction to Azure DocumentDB

Index kinds:Hash – equality queries

Applying rules

SELECT * FROM collection c WHERE c.prop = 'value'

Page 43: Introduction to Azure DocumentDB

Index kinds:Hash – equality queriesRange – range + OrderBy queries

Applying rules

SELECT * FROM collection c WHERE c.prop = 'value'SELECT * FROM collection c WHERE c.prop >= 15ORDER BY c.prop

Page 44: Introduction to Azure DocumentDB

Index kinds:Hash – equality queriesRange – range + OrderBy queriesSpatial – ST_DISTANCE, ST_WITHIN

Applying rules

SELECT * FROM collection c WHERE c.prop >= 15ORDER BY c.prop

SELECT *FROM collection cWHERE ST_DISTANCE(c.Location, { "type": "Point", "coordinates": [-122.19, 47.36]}) < 100 * 1000

Page 45: Introduction to Azure DocumentDB

Index precision:For numbers: 1-8 bytesFor strings: 1-100 bytes

Applying rules

Page 46: Introduction to Azure DocumentDB

Data consistency

Page 47: Introduction to Azure DocumentDB

•Strong consistency•Eventual consistency

DocumentDB

•Strong consistency•Eventual consistency•Session•Bounded staleness

Offered consistency models

Page 48: Introduction to Azure DocumentDB

Strong consistency

Page 49: Introduction to Azure DocumentDB

Strong consistency: Write operationVersion2

Version1

Version2

User

Replica A

Replica B

Replica CGateway

Async

Infra

Version2

Page 50: Introduction to Azure DocumentDB

Strong consistency: Read operationVersion2

Version1

Version2

User

Replica A

Replica B

Replica CGateway

Infra

Version2

Page 51: Introduction to Azure DocumentDB

Eventual consistency

Page 52: Introduction to Azure DocumentDB

Eventual consistency: Write operationVersion2

Version1

Version1

User

Replica A

Replica B

Replica CGateway

Async

Infra

Version2

Page 53: Introduction to Azure DocumentDB

Eventual consistency: Read operationVersion2

Version1

Version1

User

Replica A

Replica B

Replica CGateway

Infra

Version1

Page 54: Introduction to Azure DocumentDB

Session consistency

Page 55: Introduction to Azure DocumentDB

Session: Write operationVersion2

Version1

Version1

User

Replica A

Replica B

Replica CGateway

Async

Infra

Session Id

Version2

Page 56: Introduction to Azure DocumentDB

Session: Read operationVersion2

Version1

Version1

Replica A

Replica B

Replica CGateway

Infra

Version2User A

User B

Session Id

Version1

Page 57: Introduction to Azure DocumentDB

Bounded staleness

Page 58: Introduction to Azure DocumentDB

Bounded staleness: Write operationVersion2

Version1

Version1

User

Replica A

Replica B

Replica CGateway

Async

Infra

Version2

Page 59: Introduction to Azure DocumentDB

Bounded staleness: Read operationVersion3

Version1

Version2

User

Replica A

Replica B

Replica CGateway

Sync

Infra

Version2

Page 60: Introduction to Azure DocumentDB

Scalability issuesOut of space

>Data Collection

Page 61: Introduction to Azure DocumentDB

Scalability issues

Too many requestsOut of space

>Data Collection

Page 62: Introduction to Azure DocumentDB

Solutions?

Vertical scaling

Page 63: Introduction to Azure DocumentDB

Horizontal scalingVertical scaling

Solutions?

Page 64: Introduction to Azure DocumentDB

Collection = Partition

Page 65: Introduction to Azure DocumentDB

Collection

RequestPartitioning our data

Page 66: Introduction to Azure DocumentDB

Partition 1

Request

Request

Partition 2

Logical groupingPartitioning our data

Page 67: Introduction to Azure DocumentDB

Partitioning strategies

Hash partitioningPartition 1

Partition 3

Partition 2UserId: 14 Hash(14)=>

P3Infra

Logical grouping

Page 68: Introduction to Azure DocumentDB

Partitioning strategies

Range partitioningPartition 1

Partition 3

Partition 2Name: ͚QDavid͚R

Infra

K > ͚QDavid͚R>= A

A-I

K-Q

R-Z

Logical grouping

Page 69: Introduction to Azure DocumentDB

Partitioning strategies

Lookup partitioning

Region name Partition Id

Asia Partition1

Version3Europe Partition2

United States Partition3

Partition 1

Partition 3

Partition 2Region: ͚QEurope͚R

Infra

Logical grouping

Page 70: Introduction to Azure DocumentDB

Use Cases

Page 71: Introduction to Azure DocumentDB

Use Cases: user-defined data

Page 72: Introduction to Azure DocumentDB

Use Cases: storing and analyzing logs

Logs

Page 73: Introduction to Azure DocumentDB

Use Cases: storing materialized views


Recommended