Transcript
Page 1: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

Matt Yanchyshyn: Solutions Architect, AWS

Shekhar Deshkar: Chief Architect, Druva

Page 2: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

• What’s new

• JSON Document Support

• Flexible access control

• Partitions & Scaling

• Optimizing Data Access Cost

• Customer use case: Druva

Page 3: AWS Webcast - Dynamo DB

Fast & flexible NoSQL database

Predictable performance

Seamless & massive scalability

Fully managed; zero adminAmazon

DynamoDB

Page 4: AWS Webcast - Dynamo DB

What’s new?

• JSON Document Support

• Larger items: 400KB max item size

• Additional Scaling Options

• Expanded Free Tier: 25GB & 200M requests per month

4

Page 5: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

What’s new

• JSON Document Support

• Flexible access control

• Partitions & Scaling

• Optimizing Data Access Cost

• Customer use case: Druva

Page 6: AWS Webcast - Dynamo DB

New Data Types

• Scalars: Number, String, Binary, Boolean, Null

• Multi-value: String Set, Number Set, Binary Set

• Document: List and Map

Page 7: AWS Webcast - Dynamo DB

New Data Types

{

Day: "Monday",

FavoriteDay: false,

ItemsOnMyDesk: [

"Telephone",

{

Pens: { Quantity : 3},

Pencils: { Quantity : 2},

Erasers: null

}

]

}

Map

Boolean

Nested List

Map

Null

Page 8: AWS Webcast - Dynamo DB

Document Paths

{

Day: "Monday",

FavoriteDay: false,

ItemsOnMyDesk: [

"Telephone",

{

Pens: { Quantity : 3},

Pencils: { Quantity : 2},

Erasers: null

}

]

}

FavoriteDay

ItemsOnMyDesk[0]

ItemsOnMyDesk[1].Pens.Quantity

Page 9: AWS Webcast - Dynamo DB

Example: AWS SDK for Java Document API

Item item = new Item()

.withPrimaryKey("Day", "Monday")

.withJSON("document", json);

table.putItem(item);

Item documentItem = table.getItem(new GetItemSpec()

.withPrimaryKey("Day", ”Monday")

.withAttributesToGet("document"));

Item documentItem = table.getItem(new GetItemSpec()

.withPrimaryKey("Day", "Monday")

.withProjectionExpression("document.ItemsOnMyDesk[1].Pens.Quantity"));

{ItemsOnMyDesk=[Telephone,

{Erasers=null, Pencils={Quantity=2},

Pens={Quantity=3}}],

FavoriteDay=false}

{ItemsOnMyDesk=[{Pens=

{Quantity=3}}]}

Page 10: AWS Webcast - Dynamo DB

Example: AWS SDK for Java Document API

Item item = new Item()

.withPrimaryKey("Day", "Friday")

.withMap("document", new ValueMap()

.withBoolean("FavoriteDay", true)

.withList("ItemsOnMyDesk", "Telephone",

new ValueMap()

.withMap("Pens", new ValueMap()

.withInt("Quantity", 1))

.withMap("Pencils", new ValueMap()

.withInt("Quantity", 0))

.withMap("Erasers", new ValueMap()

.withInt("Quantity", 1))));

{Day: "Monday",FavoriteDay: false,ItemsOnMyDesk: ["Telephone",{Pens: { Quantity : 3},Pencils: { Quantity : 2},Erasers: null

}]

}

Page 11: AWS Webcast - Dynamo DB

Questions?

Page 12: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

What’s new

JSON Document Support

• Flexible access control

• Partitions & Scaling

• Optimizing Data Access Cost

• Customer use case: Druva

Page 13: AWS Webcast - Dynamo DB

Flexible access control

• Control access to individual

items and attributes

• Implement using AWS IAM

roles that authenticated

users assume

• Leverage SAML or WIF

Page 14: AWS Webcast - Dynamo DB

Flexible access control with AWS IAM

...

"Effect": "Allow",

"Action": [ "dynamodb:Query”, "dynamodb:Scan” ],

"Resource": "arn:aws:dynamodb:REGION:abcde12345:users/example",

"Condition": {

"ForAllValues:StringEquals": {

"dynamodb:LeadingKeys": ["${saml:sub}"],

"dynamodb:Attributes": [ "userId", "firstName", "lastName” ]

},

"StringEqualsIfExists": {

"dynamodb:Select": "SPECIFIC_ATTRIBUTES"

}

...

Authenticated user ID /

DynamoDB table key

Item attributes that

user can access

DynamoDB API

actions allowed

Page 15: AWS Webcast - Dynamo DB

Questions?

…and if you want to take DynamoDB’s flexible security

model to the next level, check-out client-side encryption

in Java with DynamoDBMapper:

http://bit.ly/1zerqW2

Page 16: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

What’s new

JSON Document Support

Flexible access control

• Partitions & Scaling

• Optimizing Data Access Cost

• Customer use case: Druva

Page 17: AWS Webcast - Dynamo DB

Partitions & Scaling

Votes Table

Voter

Candidate A

Votes: 21

Candidate B

Votes: 30

UpdateItem

ADD 1 to “Candidate A”

(aka Atomic Increment)

Page 18: AWS Webcast - Dynamo DB

Partitions & Scaling

Votes Table

You

Provision 1200 Write Capacity Units

Need to scale

for the election

Page 19: AWS Webcast - Dynamo DB

Partitions & Scaling

Votes Table

Partition 1 Partition 2

You

600 Write Capacity Units (each)

Provision 1200 Write Capacity Units

Page 20: AWS Webcast - Dynamo DB

Partitions & Scaling

Votes Table

Partition 1 Partition 2

You

(no sharing)

Provision 1200 Write Capacity Units

Page 21: AWS Webcast - Dynamo DB

Partitions & Scaling

Votes Table

You

Provision 200,000 Write Capacity Units

Partition 1

(600 WCU)

Partition K

(600 WCU)

Partition M

(600 WCU)

Partition N

(600 WCU)

Page 22: AWS Webcast - Dynamo DB

Partitions & Scaling

Votes Table

Partition 1

(600 WCU)

Candidate A

Partition K

(600 WCU)

Partition M

(600 WCU)

Partition N

(600 WCU)

Candidate B

Voters

Page 23: AWS Webcast - Dynamo DB

Scaling Writes

Votes Table

Candidate A_2

Candidate B_1

Candidate B_2

Candidate B_3

Candidate B_5

Candidate B_4

Candidate B_7

Candidate B_6

Candidate A_1

Candidate A_3

Candidate A_4Candidate A_7 Candidate B_8

Voter

UpdateItem: “CandidateA_” + rand(0, 10)

ADD 1 to Votes

Candidate A_6 Candidate A_8

Candidate A_5

Page 24: AWS Webcast - Dynamo DB

Scaling Writes

Votes Table

Candidate A_2

Candidate B_1

Candidate B_2

Candidate B_3

Candidate B_5

Candidate B_4

Candidate B_7

Candidate B_6

Candidate A_1

Candidate A_3

Candidate A_4

Candidate A_5

Candidate A_6 Candidate A_8

Candidate A_7 Candidate B_8

Periodic

Process

Candidate A

Total: 2.5M

1. Sum

2. StoreVoter

Page 25: AWS Webcast - Dynamo DB

Scaling Reads

Votes Table

Partition 1

(600 WCU)

Candidate A_Total

Votes: 2.5M

Partition K

(600 WCU)

Partition M

(600 WCU)

Partition N

(600 WCU)

Candidate B_Total

Votes: 2.1M

Voters

Page 26: AWS Webcast - Dynamo DB

Scaling Reads

Votes Table

Partition 1

(600 WCU)

Candidate A_Total

Votes: 2.5M

Partition K

(600 WCU)

Partition M

(600 WCU)

Partition N

(600 WCU)

Candidate B_Total

Votes: 2.1M

Voters

Page 27: AWS Webcast - Dynamo DB

Scaling Best Practices

• Design for uniform data access

• Distribute write activity

• Understand access patterns

• Be careful not to over-provision

Page 28: AWS Webcast - Dynamo DB

Questions?

Page 29: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

What’s new

JSON Document Support

Flexible access control

Partitions & Scaling

• Optimizing Data Access Cost

• Customer use case: Druva

Page 30: AWS Webcast - Dynamo DB

Optimizing Query Cost

Page 31: AWS Webcast - Dynamo DB

Provisioned Throughput Capacity Units

• 1 Write Capacity Unit (WCU) = Up to 1 KB Item

• 1 Read Capacity Unit (RCU) = Up to 4 KB of Items

• 0.5 RCU = Up to 4 KB of Items (Eventually Consistent)

Page 32: AWS Webcast - Dynamo DB

How much throughput do I need?

• Investigate customer workload:

– How many requests per second per hash key?

– How much will those operations cost?

• Investigate customer data size:

– How big will the table be initially?

– How large will the table grow?

– Will the throughput grow proportionally?

Page 33: AWS Webcast - Dynamo DB

Best practices: Query vs. BatchGetItem

• Query treats all items as a single read operation– Items share the same hash key = same partition

– BatchGetItem reads each item in the batch separately

• Example– Read 100 items in a table, all with the same hash key.

Each item is 120 bytes in size

– Query RCU = 3

– BatchGetItem RCU = 100

Page 34: AWS Webcast - Dynamo DB

Filter cost calculation

Query UserId=Alice, Filter where OpponentId=Bob

UserId GameId Date OpponentId

Carol e23f5a 2013-10-08 Charlie

Alice d4e2dc 2013-10-01 Bob

Alice e9cba3 2013-09-27 Charlie

Alice f6a3bd 2013-10-08 Bob

Filters do not reduce

the throughput cost

Query/Scan: 1 MB max

returned per operation.

Limit applies before

filtering

Page 35: AWS Webcast - Dynamo DB

Example: Query & Read Capacity Units

Page Time Views

index.html 2014-06-25T12:00 120

index.html 2014-06-25T12:01 122

index.html 2014-06-25T12:02 125

search.html 2014-06-25T12:00 200

Query PageViewsWHERE Page=index.html

AND Time >= 2014-06-25T12:00LIMIT 10 42 bytes each X 3 items

= 126 bytes

= 1 Read Capacity Unit

Page 36: AWS Webcast - Dynamo DB

Query cost calculation

UserId GameId Date OpponentId …

Carol e23f5a 2013-10-08 Charlie …

Alice d4e2dc 2013-10-01 Bob …

Alice e9cba3 2013-09-27 Bob …

Alice f6a3bd 2013-10-08

(1 item = 600 bytes)

(397 more games for Alice)

400 X 600 / 1024 / 4 = 60 Read Capacity Units

(bytes per item) (KB per byte)

(KB per Read Capacity Unit)(Items evaluated by Query)

Page 37: AWS Webcast - Dynamo DB

Local Secondary Indexes (LSI)

• Same hash key + alternate (scalar) range key

• Index and table data is co-located (same partition)

• Read and write capacity units consumed from the table

• Increases WCUs per write

• 10GB max

Page 38: AWS Webcast - Dynamo DB

A1

(hash)

A3

(range)

A2

(table key)

A1

(hash)

A2

(range)

A3 A4 A5

LSIs

A1

(hash)

A4

(range)

A2

(table key)

A3

(projected)

Table

KEYS_ONLY

INCLUDE A3

A1

(hash)

A4

(range)

A2

(table key)

A3

(projected)

A5

(projected) ALL

Local Secondary Index Projections

• Items with fewer projected attributes will be smaller: lower cost

• Project with care: LSI queries auto-fetch non-projected attributes

from the table …at a cost: index matches + table matches

Page 39: AWS Webcast - Dynamo DB

Global Secondary Indexes (GSI)

• Any attribute indexed as new hash and/or range key

• GSIs get their own provisioned throughput

• Asynchronously updated, so eventual consistency only

Page 40: AWS Webcast - Dynamo DB

A5

(hash)

A3

(range)

A1

(table key)

A1

(hash)

A2 A3 A4 A5

GSIs

A5

(hash)

A4

(range)

A1

(table key)

A3

(projected)

Table

KEYS_ONLY

INCLUDE A3

A4

(hash)

A5

(range)

A1

(table key)

A2

(projected)

A3

(projected) ALL

A2

(hash)

A1

(table key) KEYS_ONLY

Global Secondary Index Projections

GSI queries can only

request projected

attributes

Page 41: AWS Webcast - Dynamo DB

Reduce cost with Sparse Indexes

• DynamoDB only writes to an index if the index key value is present in the item

• Use sparse indexes to efficiently locate table items that have an uncommon attribute

• Example: find hockey teams that have won the Stanley Cup– GSI Hash Key: StanleyCupWinner

– GSI Range Key: TeamId

Page 42: AWS Webcast - Dynamo DB

Optimizing Scans

Page 43: AWS Webcast - Dynamo DB

What about non-indexed querying?

• Sometimes you need to scan the full table, e.g. bulk export

• Use Parallel Scan for faster retrieval, if…– Your table is >= 20 GB

– Provisioned read throughput has room

– Sequential Scan operations are too slow

• Consider cost and performance implications

Page 44: AWS Webcast - Dynamo DB

Bulk Export: Scan

Your Table

Partition 1 Partition 2 Partition 3 Partition 4

• Slow: only uses one

partition at a time

• Non-uniform utilization

• Consumes lots of

RCUs

Page 45: AWS Webcast - Dynamo DB

Bulk Export: Parallel Scan

Your Table

Partition 1 Partition 2 Partition 3 Partition 4

• Divide the work

• Use threads, non-

blocking IO, processes,

or multiple servers to

distribute the work

• Can still consume lots of

RCUs!

Page 46: AWS Webcast - Dynamo DB

Bulk Export: Rate-limited Parallel Scan

Your Table

Partition 1 Partition 2 Partition 3 Partition 4

• Limit page size and rate

(1 MB default page size

/ 4 KB item size)

/ 2 eventually consistent reads

= 128 RCUs per page (default)

• Rate-limit each segment

Page 47: AWS Webcast - Dynamo DB

Many best practices are implemented already

• Amazon Elastic Map Reduce– dynamodb.throughput.read/write.percent

• Amazon Redshift– readratio

• DynamoDB Mapper (Java SDK)

• RateLimiter library (Google Guava)

Page 48: AWS Webcast - Dynamo DB

Questions?

Page 49: AWS Webcast - Dynamo DB

Amazon DynamoDB Deep Dive

What’s new

JSON Document Support

Flexible access control

Partitions & Scaling

Optimizing Data Access Cost

• Customer use case: Druva

Page 50: AWS Webcast - Dynamo DB

Shekhar Deshkar

Chief Architect, Druva

Page 51: AWS Webcast - Dynamo DB

Reinventing Data Protection for a Mobile World

• Druva inSync Ranked #1 by Gartner, 2 successive years• Top amongst 7 products against 11 critical capabilities

• Protect & govern data at the edge of enterprises– Extend eDiscovery & corporate data governance to endpoints

– Data loss prevention in case of lost devices

• Sync-share for enterprise-wide collaboration

• Radically simple Cloud backup and Archival– Eliminates Complexity of Legacy Backup and Tape Vaulting

Page 52: AWS Webcast - Dynamo DB

Data management Challenges in a Mobile World

• Cost of managing ever-growing number of

endpoints or remote servers

• Controlling associated data growth

– Should I backup everything?

– Did I miss backing up something critical?

• Cloud?

– How do I manage prime-time WAN bandwidth

Page 53: AWS Webcast - Dynamo DB

Data backup for endpoints and at the Edge

• Backup: Data & metadata

• Incremental backup

• Data deduplication

– Global

– Source-side

Page 54: AWS Webcast - Dynamo DB

Druva Storage nCube Architecture

• Distributed Cloud File System

• Store: Object storage, single instance, self-healing

• Organize: Time-indexed views, metadata server

• Serve: Uncompromised throughput

• End-to-end Security

• At the ends: 2-factor encryption; At device

• Everything in between: Data in transit, Data access

• Designed for the Edge

• Intelligent, global de-duplication at the edge

• Flexible deployment

• Why we moved away from Cassandra:

http://aws.amazon.com/solutions/case-studies/druva/

Page 55: AWS Webcast - Dynamo DB

Druva Storage on AWS

Page 56: AWS Webcast - Dynamo DB

NoSQL Database & Distributed Systems

Scenario: Collaborators trying to create same file in shared work-space

• Need to simulate atomic operations that ensures only one of them succeeds

• Each collaborator creates an object with a unique temporary name

• Perform atomic rename (from unique temporary to possibly-conflicting name) to ensure only one succeeds.

item = self.db.new_item(self.DRSTK_FOLDER_NAMEVER, key, {self.AT_DIRENT: val})

try:item.put(expected_value={self.AT_DIRENT: False})

except adb.ConditionCheckFailedError:# someone else raced against us and # already created a folder entry we’re hoping to create

Page 57: AWS Webcast - Dynamo DB

Transactional semantics for References

• How do we implement transaction-like semantics while updating two independent DynamoDB items?

• Thread #A is trying to add reference to an existing item, stored as an object in S3, has checksum ‘csum’, and is identified by ‘handle’

• Thread #B, is in process of dropping it’s reference to the same object and if no more references, removes the item and associated S3 object too.

Page 58: AWS Webcast - Dynamo DB

Transactional semantics for References

• Thread A: Optimistically, add a new reference to the handle

hkey, rkey = self.handle2key(handle)

item = self.db.new_item(self.id_ref + hkey, rkey + reverselink,{})

item.put()

chkey, crkey = self.sum2key(csum)

try:

citem = self.db.get_item(chkey, crkey + rkey)

except adb.KeyNotFoundError:

# we lost race & handle vanished, drop our reference

item.delete()

else: # success

Label #1 thread B

may be forced to

take Label #5 path

Label #2

Page 59: AWS Webcast - Dynamo DB

Transactional semantics for References

• Thread B Drop a reference to the handle

item = self.db.new_item(self.id_ref + hkey, rkey + reverselink)

item.delete()

items = self.db.query(self.id_ref + hkey, query, limit=1)

try:

item = items.next()

except StopIteration: # no more references to the handle

else: # Additional references exist, can't purge

return 0

# No one possibly using this block

chkey, crkey = self.sum2key(csum)

item = self.db.new_item(chkey, crkey + rkey)

item.delete()

items = self.db.query(self.id_ref + hkey, query, limit=1)

try:

item = items.next()

except StopIteration: # safe to purge the block from S3 now

else: # Someone is now using this. Don't drop block Label #5

Label #4

Label #3 thread A

may be forced to

take Label #2 path

Page 60: AWS Webcast - Dynamo DB

Designing for Scale-Out Performance

• DynamoDB hot partitions

• Lock-free concurrent access

– Minimize shared state

– Identify and eliminate false-sharing

– Distinct hash keys

• Relax semantics for shared state

– Shard hash key to eliminate DynamoDB hotspots

– Collate shard state to determine global state

Page 61: AWS Webcast - Dynamo DB

Provisioned Throughput Optimization

• Application IOPs to sustain

– DynamoDB IOPs needed to support it

• Shield applications from Throttling errors

• Optimize Provisioned Throughput based on History

Page 62: AWS Webcast - Dynamo DB

Questions?

Page 63: AWS Webcast - Dynamo DB

Poll

Page 64: AWS Webcast - Dynamo DB

Thank you!

https://aws.amazon.com/dynamodb/developer-resources/

http://druva.com/


Top Related