Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. You can use Amazon DynamoDB to create a database table that can store and retrieve any amount of data, and serve any level of request traffic. Amazon DynamoDB automatically spreads the data and traffic for the table over a sufficient number of servers to handle the request capacity specified by the customer and the amount of data stored, while maintaining consistent and fast performance.
8. Data Tier
Search Cache Blob Store
RDBMSNoSQL
Data
Warehouse
logging
analy=cs
key/value
simple query
rich search
hot reads
complex queries
and transac=ons
10. database service
automated operations predictable performance
fast development
always durable
low latency cost effective
=
11.
12.
13. WRITES
Continuously replicated to 3 zones
Quorum acknowledgment
Persisted to disk (custom SSD)
READS
Strongly or eventually consistent
No trade-off in latency
22. Images Table
User Image Date Link
Bob aed4c 2013-10-01 s3://…
Bob cf2e2 2013-09-05 s3://…
Bob f93bae 2013-10-08 s3://…
Alice ca61a 2013-09-12 s3://…
Hash and range primary key schema (composite key)
23. Images Table
User Image Date Link
Bob aed4c 2013-10-01 s3://…
Bob cf2e2 2013-09-05 s3://…
Bob f93bae 2013-10-08 s3://…
Alice ca61a 2013-09-12 s3://…
Range: Index is sorted by range key, can do range queries
Hash: Equality queries only
24. Images Table
User Image Date Link
Bob aed4c 2013-10-01 s3://…
Bob cf2e2 2013-09-05 s3://…
Bob f93bae 2013-10-08 s3://…
Alice ca61a 2013-09-12 s3://…
Bob
Query for Bob’s Images
Query
FROM Images
WHERE User=Bob
25.
26.
27. Images Table
User Image Date Link
Bob aed4c 2013-10-01 s3://…
Bob cf2e2 2013-09-05 s3://…
Bob f93bae 2013-10-08 s3://…
Alice ca61a 2013-09-12 s3://…
User Date Image
Bob 2013-09-05 cf2e2
Bob 2013-10-01 aed4c
Bob 2013-10-08 f93bae
Alice 2013-09-12 ca61a
Table ByDate Local Secondary Index
Local secondary index on Date
28. Images Table
User Image Date Link
Bob aed4c 2013-10-01 s3://…
Bob cf2e2 2013-09-05 s3://…
Bob f93bae 2013-10-08 s3://…
Alice ca61a 2013-09-12 s3://…
User Date Image
Bob 2013-09-05 cf2e2
Bob 2013-10-01 aed4c
Bob 2013-10-08 f93bae
Alice 2013-09-12 ca61a
Table ByDate Local Secondary Index
Query for Bob’s
two most recent imagesQuery
FROM Image-Index
WHERE User=Bob, DESC, LIMIT 2
37. ImageTags Table
Global secondary index on User, Image
User Image
Bob aed4c
Bob f93bae
Alice aed4c
Alice f93bae
ByUser Global Secondary Index
Image User
aed4c Alice
aed4c Bob
f93bae Alice
f93bae Bob
Table
Alternate hash and range keys
38. ImageTags Table
Alice
Query for images tagged Alice
User Image
Bob aed4c
Bob f93bae
Alice aed4c
Alice f93bae
ByUser Global Secondary Index
Image User
aed4c Alice
aed4c Bob
f93bae Alice
f93bae Bob
Table
Query
FROM ImageTags-Index
WHERE User=Alice
39.
40.
41.
42. {
Id : abecd,
Players : [ Alice, Bob ],
State : STARTED,
Turn : Bob,
Top-Right : O
}
Game Item
54. Bob (1)
Bob (2)
Time
Read
Read
Version: 1
Turn: Bob
Version: 1
Turn: Bob
Version: 1
Turn: Bob
Version: 2
Turn: Alice
Top-Right: X
Version: 2
Turn: Alice
Top-Left: X
55. Bob (1)
Bob (2)
Read
Read
Version: 1
Turn: Bob
Version: 1
Turn: Bob
Version: 1
Turn: Bob
Version: 2
Turn: Alice
Top-Right: X
Version: 2
Turn: Alice
Top-Left: X
Version: 2
Turn: Alice
Top-Right: X
Put
If V=1
Time
56. Bob (1)
Bob (2)
Read
Read
Version: 1
Turn: Bob
Version: 1
Turn: Bob
Version: 1
Turn: Bob
Version: 2
Turn: Alice
Top-Right: X
Version: 2
Turn: Alice
Top-Right: X
Version: 2
Turn: Alice
Top-Right: X
Put
If V=1
Put
If V=1
Time
57. @DynamoDBTable( tableName = "TicTacToeGame" )
public class Game {
private String id;
// ... other attributes
private Long version;
@DynamoDBHashKey
public String getId() { ... }
@DynamoDBVersionAttribute
public Long getVersion() { ... }
}
58. @DynamoDBTable( tableName = "TicTacToeGame" )
public class Game {
private String id;
// ... other attributes
private Long version;
@DynamoDBHashKey
public String getId() { ... }
@DynamoDBVersionAttribute
public Long getVersion() { ... }
}
96. GameId Date Host Opponent Status
d9bl3 2014-10-02 David Alice DONE
72f49 2014-09-30 Alice Bob PENDING
o2pnb 2014-10-08 Bob Carol IN_PROGRESS
b932s 2014-10-03 Carol Bob PENDING
ef9ca 2014-10-03 David Bob IN_PROGRESS
Games Table
97. GameId Date Host Opponent Status
d9bl3 2014-10-02 David Alice DONE
72f49 2014-09-30 Alice Bob PENDING
o2pnb 2014-10-08 Bob Carol IN_PROGRESS
b932s 2014-10-03 Carol Bob PENDING
ef9ca 2014-10-03 David Bob IN_PROGRESS
Games Table
100. Secondary Index
Bob
Opponent Status GameId Date Host
Alice DONE d9bl3 2014-10-02 David
Carol IN_PROGRESS o2pnb 2014-10-08 Bob
Bob IN_PROGRESS ef9ca 2014-10-03 David
Bob PENDING 72f49 2014-10-03 Alice
Bob PENDING b932s 2014-09-30 Carol
101. Secondary Index
Opponent Status GameId Date Host
Alice DONE d9bl3 2014-10-02 David
Carol IN_PROGRESS o2pnb 2014-10-08 Bob
Bob IN_PROGRESS ef9ca 2014-10-03 David
Bob PENDING 72f49 2014-10-03 Alice
Bob PENDING b932s 2014-09-30 Carol
Bob
102. Secondary Index
Opponent Status GameId Date Host
Alice DONE d9bl3 2014-10-02 David
Carol IN_PROGRESS o2pnb 2014-10-08 Bob
Bob IN_PROGRESS ef9ca 2014-10-03 David
Bob PENDING 72f49 2014-10-03 Alice
Bob PENDING b932s 2014-09-30 Carol
Bob
SELECT * FROM Game
WHERE Opponent='Bob'
AND Status='PENDING'
103. Bob
SELECT * FROM Game
WHERE Opponent='Bob'
AND Status='PENDING'
ORDER BY Date?
Opponent Status GameId Date Host
Alice DONE d9bl3 2014-10-02 David
Carol IN_PROGRESS o2pnb 2014-10-08 Bob
Bob IN_PROGRESS ef9ca 2014-10-03 David
Bob PENDING 72f49 2014-10-03 Alice
Bob PENDING b932s 2014-09-30 Carol
Secondary Index
104. SELECT * FROM Game
WHERE Opponent='Bob'
AND Status='IN_PROGRESS'
ORDER BY Date?
(hash)
(range)
(?)
105. Secondary Index
Opponent Date GameId Status Host
Alice 2014-10-02 d9bl3 DONE David
Carol 2014-10-08 o2pnb IN_PROGRESS Bob
Bob 2014-09-30 72f49 PENDING Alice
Bob 2014-10-03 b932s PENDING Carol
Bob 2014-10-03 ef9ca IN_PROGRESS David
Bob
106. Secondary Index
Bob
Opponent Date GameId Status Host
Alice 2014-10-02 d9bl3 DONE David
Carol 2014-10-08 o2pnb IN_PROGRESS Bob
Bob 2014-09-30 72f49 PENDING Alice
Bob 2014-10-03 b932s PENDING Carol
Bob 2014-10-03 ef9ca IN_PROGRESS David
SELECT * FROM Game
WHERE Opponent='Bob'
ORDER BY Date DESC
FILTER ON Status='PENDING'
(filtered out)
112. Secondary Index
Opponent StatusDate GameId Host
Alice DONE_2014-10-02 d9bl3 David
Carol IN_PROGRESS_2014-10-08 o2pnb Bob
Bob IN_PROGRESS_2014-10-03 ef9ca David
Bob PENDING_2014-09-30 72f49 Alice
Bob PENDING_2014-10-03 b932s Carol
113. Opponent StatusDate GameId Host
Alice DONE_2014-10-02 d9bl3 David
Carol IN_PROGRESS_2014-10-08 o2pnb Bob
Bob IN_PROGRESS_2014-10-03 ef9ca David
Bob PENDING_2014-09-30 72f49 Alice
Bob PENDING_2014-10-03 b932s Carol
Secondary Index
Bob
SELECT * FROM Game
WHERE Opponent='Bob'
AND StatusDate STARTS_WITH 'PENDING'
139. David
Recipient Date Sender Message
David 2014-10-02 Bob …
… 48 more messages for David …
David 2014-10-03 Alice …
Alice 2014-09-28 Bob …
Alice 2014-10-01 Carol …
(Many more messages)
MessagesTable
140. Recipient Date Sender Message
David 2014-10-02 Bob …
… 48 more messages for David …
David 2014-10-03 Alice …
Alice 2014-09-28 Bob …
Alice 2014-10-01 Carol …
(Many more messages)
David
MessagesTable
SELECT *
FROM Messages
WHERE Recipient='David'
LIMIT 50
ORDER BY Date DESC
141. Recipient Date Sender Message
David 2014-10-02 Bob …
… 48 more messages for David …
David 2014-10-03 Alice …
Alice 2014-09-28 Bob …
Alice 2014-10-01 Carol …
(Many more messages)
David
MessagesTable
Cost of query?
SELECT *
FROM Messages
WHERE Recipient='David'
LIMIT 50
ORDER BY Date DESC
142. Recipient Date Sender Message
David 2014-10-02 Bob …
… 48 more messages for David …
David 2014-10-03 Alice …
Alice 2014-09-28 Bob …
Alice 2014-10-01 Carol …
(Many more messages)
MessagesTable
Average item size = 256 KB
Large message bodies
Attachments?
David
SELECT *
FROM Messages
WHERE Recipient='David'
LIMIT 50
ORDER BY Date DESC
143. Recipient Date Sender Message
David 2014-10-02 Bob …
… 48 more messages for David …
David 2014-10-03 Alice …
Alice 2014-09-28 Bob …
Alice 2014-10-01 Carol …
(Many more messages)
David
MessagesTable
50 items × 256 KB each
SELECT *
FROM Messages
WHERE Recipient='David'
LIMIT 50
ORDER BY Date DESC
145. Recipient Date Sender Subject MsgId
David 2014-10-02 Bob Hi!… afed
David 2014-10-03 Alice RE: The… 3kf8
Alice 2014-09-28 Bob FW: Ok… 9d2b
Alice 2014-10-01 Carol Hi!... ct7r
Inbox Table Messages Table
MsgId Body
9d2b …
3kf8 …
ct7r …
afed …
(Bulk message data)(Message metadata, indexed by recipient)
146. Recipient Date Sender Subject MsgId
David 2014-10-02 Bob Hi!… afed
David 2014-10-03 Alice RE: The… 3kf8
Alice 2014-09-28 Bob FW: Ok… 9d2b
Alice 2014-10-01 Carol Hi!... ct7r
Inbox Table Messages Table
MsgId Body
9d2b …
3kf8 …
ct7r …
afed …
David
1. Query Inbox: 1 RCU
(50 sequential items at 128 bytes)
147. Recipient Date Sender Subject MsgId
David 2014-10-02 Bob Hi!… afed
David 2014-10-03 Alice RE: The… 3kf8
Alice 2014-09-28 Bob FW: Ok… 9d2b
Alice 2014-10-01 Carol Hi!... ct7r
Inbox Table Messages Table
MsgId Body
9d2b …
3kf8 …
ct7r …
afed …
David
1. Query Inbox: 1 RCU
2. BatchGetItem Messages: 1600 RCU
(50 separate items at 256 KB)
(50 sequential items at 128 bytes)