dat302 under the covers of amazon dynamodb - aws re: invent 2012

93
Under the Covers of Amazon DynamoDB Matt Wood, Chief Data Scientist

Upload: amazon-web-services

Post on 26-Jan-2015

108 views

Category:

Documents


2 download

DESCRIPTION

Learn about the thought and decisions that went into designing and building DynamoDB. We'll talk about its roots and how we can deliver the performance and throughput you enjoy today. We’ll also show you how to model data, maintain maximum throughput, and drive analytics against the data with DynamoDB. Finally, you'll hear from some of our customers on how they've built large-scale applications on DynamoDB and about the lessons they've learned along the way.

TRANSCRIPT

Page 1: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Under the Covers of Amazon DynamoDB

Matt Wood, Chief Data Scientist

Page 2: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Hello

Page 3: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Page 4: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Two decisions + three clicks

= ready for use

Page 5: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Two decisions + three clicks

= ready for use

Primary keys

Level of throughput

Page 6: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Page 7: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Data patterns

Page 8: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Data patterns

Page 9: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

DynamoDB is a managed NoSQL

database service

Store and retrieve any amount of data

Serve any level of request traffic

Page 10: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Without the operational burden

Page 11: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Consistent, predictable performance

Single digit millisecond latency

Backed on solid-state drives

Page 12: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Flexible data model

Key/attribute pairs. No schema required.

Easy to create. Easy to adjust.

Page 13: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Seamless scalability

No table size limits. Unlimited storage.

No downtime.

Page 14: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Durable

Consistent, disk only writes

Replication across data centers

and availability zones

Page 15: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Without the operational burden

Page 16: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Without the operational burden

Focus on your app

Page 17: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Two decisions + three clicks

= ready for use

Page 18: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Page 19: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Provisioned throughput

Reserve IOPS for reads and writes

Scale up for down at any time

Page 20: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Pay per capacity unit

Priced per hour of provisioned throughput

Page 21: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Write throughput

Size of item x writes per second

$0.01 for 10 write units

Page 22: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Consistent writes

Atomic increment and decrement

Optimistic concurrency control: conditional writes

Page 23: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Transactions

Item level transactions only

Puts, updates and deletes are ACID

Page 24: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Read throughput

Strong or eventual consitency

Page 25: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Read throughput

Strong or eventual consitency

Provisioned units = size of item x reads per second

$0.01 per hour for 50 units

Page 26: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Read throughput

Strong or eventual consistency

Provisioned units = size of item x reads per second

$0.01 per hour for 100 units

2

Page 27: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Read throughput

Strong or eventual consitency

Same latency expectations

Mix and match at ‘read time’

Page 28: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Provisioned throughput is

managed by DynamoDB

Page 29: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Data is partitioned and managed

by DynamoDB

Page 30: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Achieving full provisioned throughput

requires a uniform workload

Page 31: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

The DynamoDB Uniform Workload

DynamoDB divides table data in to multiple partitions

Data is distributed primarily by primary key

Provisioned throughput is divided evenly across partitions

Page 32: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

The DynamoDB Uniform Workload

To achieve and maintain full provisioned throughput

for a table, spread the workload evenly

across primary keys

Page 33: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Non-uniform workloads

Some requests might be throttled,

even at high levels of provisioned throughput

Page 34: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Model data for a uniform workload

Page 35: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Data patterns

Page 36: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Two decisions + three clicks

= ready for use

Primary keys

Level of throughput

Page 37: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

DynamoDB semantics

Tables, items and attributes

Page 38: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

id = 100 date = 2012-05-16-09-00-

10 total = 25.00

id = 101 date = 2012-05-15-15-00-

11 total = 35.00

id = 101 date = 2012-05-16-12-00-

10 total = 100.00

id = 102 date = 2012-03-20-18-23-

10 total = 20.00

id = 102 date = 2012-03-20-18-23-

10 total = 120.00

Page 39: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

id = 100 date = 2012-05-16-09-00-

10 total = 25.00

id = 101 date = 2012-05-15-15-00-

11 total = 35.00

id = 101 date = 2012-05-16-12-00-

10 total = 100.00

id = 102 date = 2012-03-20-18-23-

10 total = 20.00

id = 102 date = 2012-03-20-18-23-

10 total = 120.00

Table

Page 40: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

id = 100 date = 2012-05-16-09-00-

10 total = 25.00

id = 101 date = 2012-05-15-15-00-

11 total = 35.00

id = 101 date = 2012-05-16-12-00-

10 total = 100.00

id = 102 date = 2012-03-20-18-23-

10 total = 20.00

id = 102 date = 2012-03-20-18-23-

10 total = 120.00

Item

Page 41: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

id = 100 date = 2012-05-16-09-00-

10 total = 25.00

id = 101 date = 2012-05-15-15-00-

11 total = 35.00

id = 101 date = 2012-05-16-12-00-

10 total = 100.00

id = 102 date = 2012-03-20-18-23-

10 total = 20.00

id = 102 date = 2012-03-20-18-23-

10 total = 120.00

Attribute

Page 42: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Items are indexed by primary key

Single hash keys and composite range keys

Page 43: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

id = 100 date = 2012-05-16-09-00-

10 total = 25.00

id = 101 date = 2012-05-15-15-00-

11 total = 35.00

id = 101 date = 2012-05-16-12-00-

10 total = 100.00

id = 102 date = 2012-03-20-18-23-

10 total = 20.00

id = 102 date = 2012-03-20-18-23-

10 total = 120.00

Hash key

Page 44: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

id = 100 date = 2012-05-16-09-00-

10 total = 25.00

id = 101 date = 2012-05-15-15-00-

11 total = 35.00

id = 101 date = 2012-05-16-12-00-

10 total = 100.00

id = 102 date = 2012-03-20-18-23-

10 total = 20.00

id = 102 date = 2012-03-20-18-23-

10 total = 120.00

Range key

Page 45: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Items are retrieved by primary key

Page 46: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Range keys for queries

For example: all items for November

Page 47: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Relationships are not hard coded,

but can be modeled

Page 48: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Players

user_id =

mza

location =

Cambridge

joined =

2011-07-04

user_id =

jeffbarr

location =

Seattle

joined =

2012-01-20

user_id =

werner

location =

Worldwide

joined =

2011-05-15

Page 49: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

user_id =

mza

location =

Cambridge

joined =

2011-07-04

user_id =

jeffbarr

location =

Seattle

joined =

2012-01-20

user_id =

werner

location =

Worldwide

joined =

2011-05-15

user_id =

mza

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

werner

location =

bejewelled

score =

55,000

Players

Scores

Page 50: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

user_id =

mza

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

werner

location =

bejewelled

score =

55,000

Players

Scores

user_id =

mza

location =

Cambridge

joined =

2011-07-04

user_id =

jeffbarr

location =

Seattle

joined =

2012-01-20

user_id =

werner

location =

Worldwide

joined =

2011-05-15

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

mza

game =

tetris

score =

9,000,000

user_id =

jeffbarr

Leader boards

Page 51: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

user_id =

mza

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

werner

location =

bejewelled

score =

55,000

Players

Scores

user_id =

mza

location =

Cambridge

joined =

2011-07-04

user_id =

jeffbarr

location =

Seattle

joined =

2012-01-20

user_id =

werner

location =

Worldwide

joined =

2011-05-15

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

mza

game =

tetris

score =

9,000,000

user_id =

jeffbarr

Leader boards

Scores by user

Page 52: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

user_id =

mza

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

werner

location =

bejewelled

score =

55,000

Players

Scores

user_id =

mza

location =

Cambridge

joined =

2011-07-04

user_id =

jeffbarr

location =

Seattle

joined =

2012-01-20

user_id =

werner

location =

Worldwide

joined =

2011-05-15

game =

angry-birds

score =

11,000

user_id =

mza

game =

tetris

score =

1,223,000

user_id =

mza

game =

tetris

score =

9,000,000

user_id =

jeffbarr

Leader boards

High scores by game

Page 53: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

NoSQL data modeling for maximal

provisioned throughput

Page 54: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Distinct values for hash keys

Hash key elements should have a high

number of distinct values

Page 55: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

user_id =

mza

first_name =

Matt

last_name =

Wood

user_id =

jeffbarr

first_name =

Jeff

last_name =

Barr

user_id =

werner

first_name =

Werner

last_name =

Vogels

user_id =

mattfox

first_name =

Matt

last_name =

Fox

... ... ...

Lots of unique user IDs: workload well distributed

Page 56: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Limited response codes: workload poorly distributed

status =

200

date =

2012-04-01-00-00-01

status =

404

date =

2012-04-01-00-00-01

status

404

date =

2012-04-01-00-00-01

status =

404

date =

2012-04-01-00-00-01

Page 57: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Data patterns

Page 58: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Data patterns

Page 59: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

NYT faбrik

AWS re:Invent – November 2012

Andrew Canaday & Michael Laing

New York Times Digital

Page 60: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

What we’ll cover

faбrik overview

Getting more out of DynamoDB with python/boto

– More throughput / provisioned capacity

– Across more endpoints / table

– More reliably and controllably

60

Page 61: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

61

Frank McCloud: “He wants more, don't you, Rocco?”

Johnny Rocco: “Yeah. That's it. More. That's right! I want more!”

James Temple: “Will you ever get enough?”

Frank McCloud: “Will you, Rocco?”

Johnny Rocco: “Well, I never have. No, I guess I won't.”

Page 62: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Takeaways

Messaging infrastructure is cool (again)

Old dogs have tricks you can apply

– The Internet is your friend

– BUT: much good computer science was done prior

– HENCE: not so readily findable

Boto is great – clone and contribute!

62

Page 63: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

NYT Mission

63

Enhance society by creating, collecting and distributing high quality

news, information and entertainment

- Distributing: publish / subscribe

- Collecting: gather / analyze

- High Quality: fast, reliable, accurate

Page 64: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik

Asynchronous Messaging Framework

For client devices as well as our apps

Enabled by:

– Websockets

– Robust message handling software

– Amazon Web Services

Focusing on simple, common services

64

Page 65: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Typical Web Architecture

Clients interact with front-end via load balancers

Front-end makes requests to back-end on behalf of client

Bottlenecks abound

Information transfer is initiated by client

65

Page 66: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Typical Request Flow

Client

Load Balancer

Front End

… Data

… API

Page 67: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Typical Response Flow

Client

Load Balancer

Front End

… Data

… API

Page 68: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik Web Architecture

Clients interact with the nearest “App Buddy” front-end

The “App Buddy” is connected to the “Bad Rabbit” backbone

The “Bad Rabbit” backbone is clustered regionally and federated globally

NYT content producers connect directly to the backbone

Information flow is bidirectional and event-driven

68

Page 69: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik Information Flow

69

NYT

Internal

Client

Client Client

Globally distributed

“faбrik ” layer

Page 70: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik – basic

70

App

App

App

Message Broker

Page 71: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik – basic

71

App

App

App

Message Broker

Amazon Web Services

• EC2

• S3

• Identity & Access

Mgt

• DynamoDB

• Route 53

Page 72: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik – basic++

72

OtherAp

p

App

Buddy Service

Buddy

Message Broker

Message Broker

Service

Buddy

“Retail”

“Wholesale”

Page 73: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik: Current Implementation

73

Open source:

– Erlang/OTP 14B04

– RabbitMQ 2.8.7/3.pre

– Nodejs 8.xx

– Sockjs (websockets +)

– Python 2.6/2.7

– ZeroMQ

Automated deployment using CloudFormation

DynamoDB & S3 for persistence

Page 74: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik – active/active cluster

74

Service

Buddy

‘a’

Service

Buddy

‘b’

Zone ‘a’ Zone ‘b’

Region Wherever

Page 75: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik – active/active cluster

75

Service

Buddy

‘a’

Service

Buddy

‘b’

Zone ‘a’ Zone ‘b’

Region Wherever

Page 76: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

76

Page 77: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

faбrik

77

Page 78: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

78

Page 79: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

79

Page 80: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

So why DynamoDB?

faбrik services are reliable but stateless (mostly)

A happy faбrik has short queues (measurable by the way)

So persist everything as rapidly as possible (enter DynamoDB)

Plus we want to gather & analyze

– Pulse: Map / Reduce, rapid cycle

– Longitudinal analysis

– Complex Event Processing in parallel (maybe)

Note: the faбrik is asynchronous and facilitates parallelization

80

Page 81: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

DynamoDB requirements

Store all messages crossing each ‘virtual host’

Note: think of a ‘virtual host’ as a horizontal band of related, reliable

services/endpoints across zones/instances in a region

Store log messages for all application and system instances

Facilitate ‘burst’ loads as well as steady state

Support gather / analyze for all of the above

Generational storage: DDB to S3 to Glacier (with some weeding)

Fairly allocate resources among many competing endpoints

81

Page 82: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

82

Conventional wisdom…

Uh oh – we have an unpredictable mix of all these…

Page 83: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

More conventional wisdom…

“In addition to simple retries, we recommend using an exponential backoff algorithm

for better flow control. The concept behind exponential backoff is to use progressively

longer waits between retries for consecutive error responses. For example, up to 50

milliseconds before the first retry, up to 100 milliseconds before the second, up to 2400

milliseconds before third, and so on. However, after a minute, if the request has not

succeeded, the problem might be the request size exceeding your provisioned

throughput, and not the request rate. Set the maximum number of retries to stop around

one minute. If the request is not successful, investigate your provisioned throughput

options.” [i.e. increase provisioned throughput – hmmmm…]

83

Page 84: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

So…

We would have to provision for peaks

Exponential backoff would give us about a 1 minute buffer

But! The faбrik does buffering and we can monitor queue lengths

Plus we have asynchronous event scheduling/handling facilities built in…

84

Page 85: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

First strategy

With node.js, asynchronously blast all requests at dynamo, reschedule exponentially

based on backpressure

This worked pretty well!

– * Dynamo would deliver about 3 times stated capacity in bursts

– Nothing got lost

– Converged reasonably onto table capacity

But…

– Problems exerting backpressure on the faбrik from node.js… hence requests could get scheduled

WAY into el futuro… and WAY out of order

– Competition among endpoints was ‘unfair’ and fostered convergence problems

85

Page 86: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Current strategy

Be smarter, look for similar patterns and tested solutions, plus select tools that give

the right level of control

Old dog:

– “I remember when TCP was new and throughput was not very high…”

(time passes)

– “The ‘ThroughputExceeded’ backpressure from DynamoDB is sort of like TCP backpressure…”

(more time passes)

– “Perhaps we could leverage that thought by applying the research and practices that have

improved TCP etc. to our use of DynamoDB.”

(time for a nap)

86

Page 87: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Current strategy

Be smarter, look for similar patterns and tested solutions, plus select tools that give

the right level of control

Token Bucket (circa 1986) for traffic shaping

“…an algorithm used in packet switched computer networks and telecommunications networks to

check that data transmissions conform to defined limits on bandwidth and burstiness.” – Wikipedia

Additive Increase/Multiplicative Decrease (AIMD)

“…a feedback control algorithm best known for its use in TCP congestion control…combines linear

growth of the congestion window with an exponential reduction when congestion takes place…flows

will eventually converge to use equal amounts of a contended link.” – Wikipedia

Explicit Congestion Notification (ECN) etc. etc.

87

Page 88: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Current strategy

Be smarter, look for similar patterns and tested solutions, plus select reliable tools

that give the right level of control

Tools:

– Use python to get a more mature and lower level event-driven interface (pika) to RabbitMQ –

easier to exert backpressure on the message source

– Use boto to get a mature interface to DynamoDB that can be easily ‘tweaked’ to give better

information about backpressure from DynamoDB (ThroughputExceeded exception)

– Use python’s concurrent futures to easily add asynchronous capability to boto, making use of

boto’s connection pooling

88

Page 89: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Managed Access to DynamoDB

89

Page 90: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Placeholder

Here we show some code, describe the testing methodology briefly, and show

generated results.

90

Page 91: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Amazon DynamoDB

Provisioned

throughput

Data patterns

Page 92: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

Thank you!

[email protected]

@mza

Page 93: DAT302 Under the Covers of Amazon DynamoDB - AWS re: Invent 2012

We are sincerely eager to

hear your FEEDBACK on this

presentation and on re:Invent.

Please fill out an evaluation

form when you have a

chance.