Upload
marco-parenzan
View
195
Download
1
Embed Size (px)
Citation preview
« »
Azure DocumentDb Training – Resource Model
How do we model Data inside DocumentDb?
Azure DocumentDb Training – Resource Model
Recap: Why DocumentDb
Resource Model
Document and Resource Units
Database Account, Accessibility and Consistency
Database and Namespace
Containers and Partitioning
Conclusions
Azure DocumentDb Training – Resource Model
Recap: why DocumentDb
Azure DocumentDb Training – Resource Model
Set of principles that can be satisfied by a Distributed System
Consistency:All nodes should see the same data at the same time
"Result is always up to date" (no out-of-date data / stale data)
Availability:Every request receives a response about whether it succeeded or failed
"There is always a result" (accepting out-of-date data / stale data)
Partition-tolerance:The system continues to operate despite arbitrary partitioning due to network failures
"Data can be given one of multiple nodes" (some nodes can be out-of-date/ stale)
A distributed system can satisfy any two of these principles at the same time, but not all three
Azure DocumentDb Training – Resource Model
A DBMS is a Distributed SystemIt lives under CAP Theorem
A DBMS needs to choose loosing one of the three principles:A Relational DBMS chooses loosing partitioning to guarantee strict consistency and
availability
A No-Sql DBMS typically chooses moving to eventual consistency (relaxing, not
loosing) to guarantee partitioning and availability (it complains Stale Data)
Azure DocumentDb Training – Resource Model
With Eventual Consistency, a DBMS cannot run some typical
relational featuresreferential integrity
check constraints
schema
Azure DocumentDb Training – Resource Model
DocumentDb is a schemaless Db
DocumentDb is a Document-Oriented DbDocument is JSON Document
Promote code first development (mapping objects to json)
Resilient to iterative schema changes
No ORM required
It’s great for Catalog Data, Preference and State, Event Store,
User Generated Content, Data Exchange
Azure DocumentDb Training – Resource Model
Resource Model
Azure DocumentDb Training – Resource Model
DocumentDb is Platform as a ServiceNo OnPremise
RESTful APIAll DocDb elements public and accessible as Resource Uri
ResourceJson Resources
Azure DocumentDb Training – Resource Model
Azure DocumentDb Training – Resource Model
Documents
Azure DocumentDb Training – Resource Model
JS
JS
JS
101010
{
"id" : "123"
"name" : "joe"
"age" : 30
"address" : {
"street" : "some st"
}
}
Azure DocumentDb Training – Resource Model
Come as you are
Data normalization
Azure DocumentDb Training – Resource Model
embed reference
Azure DocumentDb Training – Resource Model
Representing one-to-many relationships.
Representing many-to-many relationships.
Related data changes frequently.
Referenced data could be unbounded
Provides more flexibility than embeddingMore round trips to read data
Normalizing typically provides better write performance
Azure DocumentDb Training – Resource Model
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.
There is embedded data that is integral to data in a document.
Azure DocumentDb Training – Resource Model
Resource Unit
DocumentDb is Platform as a Service: no perception of physical resource allocation
A throughput currency
1RU: ability of reading a 1Kb Json document
Many factors impacting RU usage: Document size. Document property count. Data consistency. Indexed properties. Document indexing. Query patterns. Script usage.
Reservation ModelYou are billed for the amount of throughput reserved for the collection, regardless of how much of that throughput is actively used.
There is a pricing calculator available to help calculating costs
https://www.documentdb.com/capacityplanner
Azure DocumentDb Training – Resource Model
demo
Estimating cost for a
docucument
Azure DocumentDb Training – Resource Model
Database Account
Azure DocumentDb Training – Resource Model
Unit of Autorization
Unit of Consistency
JS
JS
JS
101010
Azure DocumentDb Training – Resource Model
Master keysUpon creation of a DocumentDB account, two master keys (primary and secondary) are created. These keys enable full administrative access to all resources within the DocumentDB account.
Read-only keysUpon creation of a DocumentDB account, two read-only keys (primary and secondary) are created. These keys enable read-only access to all resources within the DocumentDBaccount.
Resource tokensA resource token is associated with a DocumentDB permission resource and captures the relationship between the user of a database and the permission that user has for a specific DocumentDB application resource (e.g. collection, document).
Azure DocumentDb Training – Resource Model
Query / transaction throughput (and reliability – i.e., hardware
failure) depend on replication!All writes to the primary are replicated across two secondary replicas
All reads are distributed across three copies
“Scalability of throughput” – allowing different clients to read from different replicas
helps prevent bottlenecks
BUT replication takes time!Potential scenario: some clients are reading while another is writing
Now, the data is stale (out-of-date), inconsistent!
Azure DocumentDb Training – Resource Model
Trade-off: speed (performance & availability) or consistency (data correctness)?“Does every read need the MOST current data?”
“Or do I need every request to be handled and handled quickly?”
4 options …Strong, Session, Bounded Staleness, Eventual
Default consistency for the entire Db…
At collection basis in a future release
On query basis (optional parameter on CreateDocumentQuery method)
Azure DocumentDb Training – Resource Model
demo
Creating a DocumentDb
Database Account
Azure DocumentDb Training – Resource Model
Database
Azure DocumentDb Training – Resource Model
Unit of Namespace
JS
JS
JS
101010
Azure DocumentDb Training – Resource Model
demo
Creating a DocumenDb
Database
Azure DocumentDb Training – Resource Model
Collections
Azure DocumentDb Training – Resource Model
A unit of scale for transactionfor stored procedures and triggers
A unit of query throughputcapacity units allocated uniformly across all collections)
A unit of replicationA collection is replicated three times
A container of JSON documentsJSON docs inside of a collection can vary dramatically
JS
JS
JS
101010
Azure DocumentDb Training – Resource Model
Collection-based RU ReservationCapacity units allocated uniformly across all collections)
Standard pricing tier with hourly billing$0.042/hour for mimimum 400RU/s
Performance levels can be adjusted
Each collection = 10GB of SSDLimit of 100 collections (1 TB)
Soft limit, can be lifted as needed per account (with Support)
Azure DocumentDb Training – Resource Model
Partitioning
Data SizeA single collection (currently*) holds 10GB
Throughput3 Performance tiers with a max of 2,500 RU/sec
Azure DocumentDb Training – Resource Model
demo
Creating a DocumenDb
Collection
Azure DocumentDb Training – Resource Model
Conclusions
Azure DocumentDb Training – Resource Model
DocumentDb is a Restful service
Documents defines Unit of Costs with Resource Units
Database Account defines Accessibility and Consistency
Database is a Namespace placeholder
Containers is the unit of Scale