SlideShare a Scribd company logo
1 of 75
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Advanced Design Patterns for Amazon
DynamoDB
P A D M A M A L L I G A R J U N A N
R E G I S G I M E N I S
R I C K H O U L I H A N
A W S P r o f e s s i o n a l S e r v i c e s
D A T 4 0 5
N o v e m b e r 3 0 , 2 0 1 7
AWS re:INVENT
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Environment Setup (15 minute)
1. Open https://tinyurl.com/awsddbwks
2. Under “Preparation,” run Steps 1-8.
3. Stuck on Step1? Raise your hands.
DAT 405 - Workshop on Advanced Design
Patterns for Amazon DynamoDB
Prerequisites:
1. Laptop
2. Basic
understanding
of DynamoDB
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Advanced Design Patterns for Amazon
DynamoDB
P A D M A M A L L I G A R J U N A N
R E G I S G I M E N I S
R I C K H O U L I H A N
A W S P r o f e s s i o n a l S e r v i c e s
D A T 4 0 5
N o v e m b e r 3 0 , 2 0 1 7
AWS re:INVENT
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AGENDA
• Prerequisites for the workshop
• Key DynamoDB concepts
• Tenets of NoSQL data modeling
• Workshop (2 hours, 7 labs)
• Design patterns - m:n relationships, index
overloading, sparse indexes, locking, adjacency
lists, DynamoDB Streams
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AMAZON DYNAMODB - KEY CONCEPTS
Document or Key-Value
Scales to Any Workload
Fully Managed NoSQL
Access Control
Event-Driven Programming
Fast and Consistent
Table
Items
Attributes
Partition
Key
Sort
Key
• Local Secondary Index
• Global Secondary Index
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Selecting a Partition Key
• Large number of distinct
values
• Values are uniformly
requested, at random
AMAZON DYNAMODB - KEY CONCEPTS
Selecting a Sort Key
• Model 1:n and m:n
relationships
• Query across entity types
• Efficient/selective queries
• Range queries
Examples:
• Bad: Status, Gender
• Good: CustomerId, DeviceId
Examples:
• Orders and OrderItems per
Customer
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Understand the use case
• Identify the access patterns
• Read/Write workloads
• Query dimensions and
aggregations
• Data-modeling
• Using NoSQL design patterns
• Review -> Repeat -> Review
TENETS OF DYNAMODB DATA MODELING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Understand the use case
• Identify the access patterns
• Read/Write workloads
• Query dimensions and
aggregations
• Data-modeling
• Using NoSQL design patterns
• Review -> Repeat -> Review
• Nature of the data
• OLTP / OLAP / full-text search
• Relationships between the entities
• What does concurrent access look like?
• Time series data
• Archiving needs, etc.
TENETS OF DYNAMODB DATA MODELING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Understand the use case
• Identify the access patterns
• Read/Write workloads
• Query dimensions and
aggregations
• Data-modeling
• Using NoSQL design patterns
• Review -> Repeat -> Review
• Source Data analysis (write workload)
• Reading one item vs multiple items
(read workload)
• Query aggregations and KPIs
TENETS OF DYNAMODB DATA MODELING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Understand the use case
• Identify the access patterns
• Read/Write workloads
• Query dimensions and
aggregations
• Data-modeling
• Using NoSQL design patterns
• Review -> Repeat -> Review
TENETS OF DYNAMODB DATA MODELING
• 1-1, 1-m, n-m relationships
• 1 application = 1 table
• Avoid unnecessary fetches
• Simplify access patterns
• Identify Primary Key
• Partition-Key and Sort-Key
• Query dimensions using LSIs and GSIs
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Understand the use case
• Identify the access patterns
• Read/Write workloads
• Query dimensions and
aggregations
• Data-modeling
• Using NoSQL design patterns
• Review -> Repeat -> Review
TENETS OF DYNAMODB DATA MODELING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Local Secondary Index Global Secondary Index
CAPACITY PLANNING FOR INDEXES
• Index is local to the partition
• Data size per partition <10GB
• Index across partitions
• Eventually consistent
• Consumes RCUs/WCUs from the
table’s provisioning
• RCUs/WCUs are provisioned separately
for GSIs
If GSIs don’t have enough write capacity, table writes will be throttled!
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Throughput
§ Provision any amount of throughput to a table
Size
§ Add any number of items to a table
- Max item size is 400 KB
- LSIs limit the number of range keys due to 10 GB limit
Scaling is achieved through partitioning
SCALING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
PARTITIONING MATH
Number of Partitions
By Capacity (Total RCU / 3000) + (Total WCU / 1000)
By Size Total Size / 10 GB
Total Partitions CEILING(MAX (Capacity, Size))
In the future, these details might change…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
PARTITIONING EXAMPLE
Table size = 8 GB, RCUs = 5000, WCUs = 500
RCUs per partition = 5000/3 = 1666.67
WCUs per partition = 500/3 = 166.67
Data/partition = 10/3 = 3.33 GB
RCUs and WCUs are uniformly
spread across partitions
Number of Partitions
By Capacity (5000 / 3000) + (500 / 1000) = 2.17
By Size 8 / 10 = 0.8
Total Partitions CEILING(MAX (2.17, 0.8)) = 3
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
0
400
800
1200
1600
CapacityUnits
Time
Provisioned Consumed
“Save up” unused
capacity
Consume saved-up capacity
Burst: 300 seconds
(1200 × 300 = 360k CU)
BURST CAPACITY IS BUILT-IN
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ADAPTIVE THROUGHPUT
Helped over 2800 Amazon tables & indexes on Prime Day!
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minutes per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
WORKSHOP
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Exercise #1 - DynamoDB Capacity Units &
Partitioning (20 minutes)
What you’ll learn:
• Tables with lower WCUs
• Write a smaller data set
• Write larger data sets at high velocity
• Burst capacity
• Behavior when dialing up capacity
• Under-provisioned WCUs on a GSI
• Viewing these metrics on Cloudwatch
WORKSHOP
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DYNAMODB SCAN OPERATIONS
• Access every item in a table on an index
• Read 1MB data in each operation
• Use LastEvaluatedKey to continue..
• Reads up to the max throughput of a single partition
• Parallel scans vs Sequential scans
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
PARALLEL SCAN
• Read all the items of a table faster
• Take advantage of the table’s provisioned capacity
• Set TotalSegments = number of application workers, each worker scans a
different segment
All Data items
Segment 0 Segment 1 Segment 2
Worker-0 Worker-1 Worker-2
Application - Main thread
Worker-3
Segment 3
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The upcoming lab…
Scenario:
Scan Server logs data for response code = OK
• Sequential Scan
fe = "responsecode <> :f"
eav = {":f": 200}
response = table.scan(
FilterExpression=fe,
ExpressionAttributeValues=eav,
Limit=pageSize
)
• Parallel Scan
fe = "responsecode <> :f"
eav = {":f": 200}
response = table.scan(
FilterExpression=fe,
ExpressionAttributeValues=eav,
Limit=pageSize,
TotalSegments=totalsegments,
Segment=threadsegment
)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
Exercise #2 – DynamoDB scans – Sequential &
Parallel table scan (10 minutes)
What you’ll learn:
• Time a sequential (simple) scan vs a parallel
scan.
• Populate a table with a large data set.
• Scan and compare run times.
• Time difference will be significant for
larger data sets.
• Don’t forget to review the Python scripts!
WORKSHOP
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: GSI OVERLOADING
• Working with the 5 GSIs limitation
• Overload attribute values based on an item’s context
Example: Query Employee Database by (1) Employee Name (2) Desk
(3) Hire Date (4) Quarterly Sales (5) Current Job role
(6) Employees in a City (7) Warehouse Location (8) Employee ID
…. and many more
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: GSI OVERLOADING
Example: Query Employee Database by (1) Employee Name (2) Warehouse
(3) Hire Date (4) Quarterly Sales
Partition Key = “Employee ID”
Sort Key = (Let’s look at final design)
DynamoDB Table design…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: GSI OVERLOADING
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
DATA MODELING: GSI OVERLOADING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
DATA MODELING: GSI OVERLOADING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
DATA MODELING: GSI OVERLOADING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
DATA MODELING: GSI OVERLOADING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
DATA MODELING: GSI OVERLOADING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
DATA MODELING: GSI OVERLOADING
Partition Key = “Employee ID”
Sort Key = Use a generic attribute-name “A”
Value is based on the item type.
Create a GSI on “A”.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Exercise #3 – GSI Overloading (15 minute)
What you’ll learn:
• Load the Employee data, create an
overloaded-GSI, and query the results!
WORKSHOP
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: SPARSE INDEXES
• Saves WCUs
• Selective querying
Example: Investigators use a GSI to query “Assigned” Cases
A
U
D
I
T
S
Primary	Key
Attributes
CaseID Item
CASE1
DETAILS1
Assignee Tags ASIN OrderID
INV1
Assignee Metadata
INV1#AUDIT1
Assignee Status_Date Type TicketID
ASSIGNED_2017-08-08	T1
INV1#AUDIT2
Assignee Status_Date Type TicketID
COMPLETED_2017-08-08	T1
INV1#AUDIT3
Assignee Status_Date Type TicketID
POST-AUDIT_2017-08-08	T1
INV1#AUDIT4
Assignee Status_Date Type TicketID
ARCHIVED_2017-08-08	T1
S31
S3Datapoints
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: SPARSE INDEXES
Example: Investigators use a GSI to query “Assigned” Cases
A
U
D
I
T
S
Primary	Key
Attributes
CaseID Item
CASE1
DETAILS1
Other	attributes
INV1
Other	attributes
INV1#AUDIT1
ASSIGNEE STATUS_DATE
ASSIGNED_2017-08-08	T1
INV1#AUDIT2
ASSIGNEE STATUS_DATE
COMPLETED_2017-08-08	T1
INV1#AUDIT3
ASSIGNEE STATUS_DATE
POST-AUDIT_2017-08-08	T1
INV1#AUDIT4
ASSIGNEE STATUS_DATE
ARCHIVED_2017-08-08	T1
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: SPARSE INDEXES
Example: Investigators use a GSI to query “Assigned” Cases
A
U
D
I
T
S
Primary	Key
Attributes
CaseID Item
CASE1
DETAILS1
Other	attributes
INV1
Other	attributes
INV1#AUDIT1
ASSIGNEE	(GSI-PK) STATUS_DATE	(GSI-SK)
ASSIGNED_2017-08-08	T1
INV1#AUDIT2
ASSIGNEE	(GSI-PK) STATUS_DATE	(GSI-SK)
COMPLETED_2017-08-08	T1
INV1#AUDIT3
ASSIGNEE	(GSI-PK) STATUS_DATE	(GSI-SK)
POST-AUDIT_2017-08-08	T1
INV1#AUDIT4
ASSIGNEE	(GSI-PK) STATUS_DATE	(GSI-SK)
ARCHIVED_2017-08-08	T1
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: SPARSE INDEXES
Example: Investigators use a GSI to query “Assigned” Cases
A
U
D
I
T
S
Primary	Key
Attributes
CaseID Item
CASE1
DETAILS1
Other	attributes
INV1
Other	attributes
INV1#AUDIT1
ASSIGNEE GSI_STATUS_DATE Status_Date
ASSIGNED_2017-08-08	T1 ASSIGNED_2017-08-08	T1
INV1#AUDIT2
Assignee Status_Date
COMPLETED_2017-08-08	T1
INV1#AUDIT3
Assignee Status_Date
POST-AUDIT_2017-08-08	T1
INV1#AUDIT4
Assignee Status_Date
ARCHIVED_2017-08-08	T1
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: SPARSE INDEXES –
ANOTHER EXAMPLE
Id	
(Partition)
User Game Score Date Award
1 Bob G1 1300 2012-12-23
2 Bob G1 1450 2012-12-23
3 Jay G1 1600 2012-12-24
4 Mary G1 2000 2012-10-24 Champ
5 Ryan G2 123 2012-03-10
6 Jones G2 345 2012-03-20
Game-scores-table
Award	
(Partition)
Id User Score
Champ 4 Mary 2000
Award-GSI
Scan sparse GSIs
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Exercise #4 – Sparse Indexes (15 minute)
What you’ll learn:
• Create a GSI on an existing table (this step
takes a few minutes)
• Review the use case for using a sparse index
• Take advantage of sparse Indexes!
WORKSHOP
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
• Define hierarchical relationships
• Execute selective queries
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
Multivalue sorts and filters
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
Partition key Sort key
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
Approach 1 : Query Filter
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
SELECT * FROM Game
WHERE Opponent='Bob'
ORDER BY Date DESC
FILTER ON Status='PENDING'
Bob
(filtered out)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
Approach 2 : Composite Sort Keys
StatusDate
DONE_2014-10-02
IN_PROGRESS_2014-10-08
IN_PROGRESS_2014-10-03
PENDING_2014-09-30
PENDING_2014-10-03
Status
DONE
IN_PROGRESS
IN_PROGRESS
PENDING
PENDING
Date
2014-10-02
2014-10-08
2014-10-03
2014-10-03
2014-09-30
+ =
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
Approach 2 : Composite Sort Keys
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
Partition key Sort key
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
Approach 2 : Composite Sort Keys
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 BEGINS_WITH 'PENDING'
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
• Define hierarchical relationships
• Execute selective queries
Example: Query Amazon buildings by Country, State, City, Office Location
Partition Key = “USA”
Sort Key = “TX”CONCAT ( , “AUSTIN”, “AUS-007” )
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
• Define hierarchical relationships
• Execute selective queries
Example: Query Amazon buildings by State, City, Office Location
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: COMPOSITE SORT KEYS
• Use composite sort key to define a hierarchy
• Highly selective queries with sort conditions
• Reduce query complexity
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Exercise #5 – Composite Sort Keys (15 minute)
What you’ll learn:
• Query Employees data using State, City,
Department.
• Create a GSI on PartitionKey=State;
SortKey=City#Dept.
• If the attribute doesn’t exist, you have to
add it to the table.
• Recap: In the real world, understand all the
access patterns to design your table
WORKSHOP
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: ADJACENCY LISTS
• Easily model many-to-many relationships
• Without excessive data duplication
Example: An invoice contains many bills. A bill can be broken up into
multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID
(2,) Get invoices by BillID
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: ADJACENCY LISTS
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
Primary	Key
Attributes
ID Item
INVOICE1
INVOICE1
Other	Invoice	Attributes
BILL1
Bill-Invoice	Attributes
BILL2
Bill-Invoice	Attributes
BILL1 BILL1
Other	Bill	Attributes
BILL2 BILL1
Other	Bill	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: ADJACENCY LISTS
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
Primary	Key
Attributes
ID Item
INVOICE1
INVOICE1
Other	Invoice	Attributes
BILL1
Bill-Invoice	Attributes
BILL2
Bill-Invoice	Attributes
BILL1 BILL1
Other	Bill	Attributes
BILL2 BILL1
Other	Bill	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: ADJACENCY LISTS
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
Primary	Key
Attributes
ID Item	(GSI-PK)
INVOICE1
INVOICE1
Other	Invoice	Attributes
BILL1
Bill-Invoice	Attributes
BILL2
Bill-Invoice	Attributes
BILL1 BILL1
Other	Bill	Attributes
BILL2 BILL2
Other	Bill	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: ADJACENCY LISTS
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
GSI	Primary	Key
Projected	Attributes
Item
INVOICE1
ID Item Other	Invoice	Attributes
INVOICE1 INVOICE1
BILL1
ID Item Bill-Invoice	Attributes
INVOICE1 BILL1
ID Item Other	Bill	Attributes
BILL1 BILL1
BILL2
ID Item Bill-Invoice	Attributes
INVOICE1 BILL2
ID Item Other	Bill	Attributes
BILL2 BILL2
Secondary index
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: LOCKING
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
(3,) Modify an invoice within a transaction
Primary	Key
Attributes
ID Item
INVOICE1
INVOICE1
Other	Invoice	Attributes
BILL1
Bill-Invoice	Attributes
BILL2
Bill-Invoice	Attributes
BILL1 BILL1
Other	Bill	Attributes
BILL2 BILL1
Other	Bill	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: LOCKING
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
(3,) Modify an invoice within a transaction
Primary	Key
Attributes
ID Item
INVOICE1
INVOICE1
LOCK Other	Invoice	Attributes
0/1
BILL1
Bill-Invoice	Attributes
BILL2
Bill-Invoice	Attributes
BILL1 BILL1
Other	Bill	Attributes
BILL2 BILL1
Other	Bill	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: VERSIONING
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
(3,) Modify an invoice within a transaction (4,) Versioning (history of Invoice updates)
Primary	Key
Attributes
ID Item
INVOICE1
v0-INVOICE1
LOCK Other	Invoice	Attributes
0/1
v1-INVOICE1
Other	Invoice	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: VERSIONING
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
(3,) Modify an invoice within a transaction (4,) Versioning (history of Invoice updates)
Primary	Key
Attributes
ID Item
INVOICE1
v0-INVOICE1
LOCK Other	Invoice	Attributes
0/1
v1-INVOICE1
Other	Invoice	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: VERSIONING
Example: An invoice contains many bills. A bill can be broken up into multiple invoices.
Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
(3,) Modify an invoice within a transaction (4,) Versioning (history of Invoice updates)
Primary	Key
Attributes
ID Item
INVOICE1
v0-INVOICE1
LOCK Other	Invoice	Attributes
0/1
v1-INVOICE1
Other	Invoice	Attributes
v2-INVOICE1
Other	Invoice	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DATA MODELING: VERSIONING
Primary	Key
Attributes
ID Item
INVOICE1
v0-INVOICE1
LOCK Other	Invoice	Attributes
0/1
v0-BILL1
Bill-Invoice	Attributes
v0-BILL2
Bill-Invoice	Attributes
v1-INVOICE1
Other	Invoice	Attributes
v1-BILL1
Bill-Invoice	Attributes
v2-INVOICE1
Other	Invoice	Attributes
v2-BILL1
Bill-Invoice	Attributes
v2-BILL2
Bill-Invoice	Attributes
BILL1 v0-BILL1
Other	Bill	Attributes
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In the upcoming lab…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Exercise #6 – Locking (10 minute)
What you’ll learn:
• Lock an employee record, and prevent dirty
writes.
• After successful obtaining a lock, make the
changes, then release the lock.
• Recap: In the real-world, understand all the
access patterns to design your table
WORKSHOP
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DYNAMODB STREAMS AND AWS LAMBDA
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DYNAMODB STREAMS AS TRIGGERS
Lambda function
Notify change
Item/Table Level Metrics
Amazon CloudSearch
Kinesis Firehose
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Exercise #7 – DynamoDB Streams & Lambda
(10 minutes)
What you’ll learn:
• Build a replication workflow
• Enable Streams on the tlog table
• Create a replication target
• Create a Lambda function (with IAM
policies) to read the streams and write to
the target
WORKSHOP
AWS STAFF IN THE ROOM
• Rick Houlihan
• Regis Gimenis
• Sean Shriver
• Edin Zulich
WORKSHOP STRUCTURE
• 7 Labs
• ~15 minute per Lab
• Raise your hands for questions
• Staying in sync with the group
• Review the Python scripts
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
D A T 4 0 5 – A d v a n c e d D e s i g n P a t t e r n s f o r A m a z o n D y n a m o D B
P A D M A M A L L I G A R J U N A N * R E G I S G I M E N I S * R I C K H O U L I H A N
thank you!
Please fill out the evaluations :)

More Related Content

What's hot

Introduction to azure cosmos db
Introduction to azure cosmos dbIntroduction to azure cosmos db
Introduction to azure cosmos dbRatan Parai
 
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인Amazon Web Services Korea
 
Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...
Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...
Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...Amazon Web Services
 
Getting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCacheGetting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCacheAmazon Web Services
 
Dynamodb Presentation
Dynamodb PresentationDynamodb Presentation
Dynamodb Presentationadvaitdeo
 
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교Amazon Web Services Korea
 
Introduction to Amazon Kinesis Firehose - AWS August Webinar Series
Introduction to Amazon Kinesis Firehose - AWS August Webinar SeriesIntroduction to Amazon Kinesis Firehose - AWS August Webinar Series
Introduction to Amazon Kinesis Firehose - AWS August Webinar SeriesAmazon Web Services
 
데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...
데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...
데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...Amazon Web Services Korea
 
AWS Identity, Directory, and Access Services: An Overview
AWS Identity, Directory, and Access Services: An Overview AWS Identity, Directory, and Access Services: An Overview
AWS Identity, Directory, and Access Services: An Overview Amazon Web Services
 
Elastic Load Balancing Deep Dive - AWS Online Tech Talk
Elastic  Load Balancing Deep Dive - AWS Online Tech TalkElastic  Load Balancing Deep Dive - AWS Online Tech Talk
Elastic Load Balancing Deep Dive - AWS Online Tech TalkAmazon Web Services
 
복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021
복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021
복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021AWSKRUG - AWS한국사용자모임
 
DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환
DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환
DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환Amazon Web Services Korea
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Web Services
 
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인Amazon Web Services Korea
 
[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기
[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기
[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기NHN FORWARD
 
Exact Microsoft AZ-900 Questions And Answers
Exact Microsoft AZ-900 Questions And AnswersExact Microsoft AZ-900 Questions And Answers
Exact Microsoft AZ-900 Questions And AnswersArmstrongsmith
 

What's hot (20)

Introduction to azure cosmos db
Introduction to azure cosmos dbIntroduction to azure cosmos db
Introduction to azure cosmos db
 
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
 
AWS DynamoDB and Schema Design
AWS DynamoDB and Schema DesignAWS DynamoDB and Schema Design
AWS DynamoDB and Schema Design
 
Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...
Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...
Building a Messaging Application with Redis Streams (DAT353) - AWS re:Invent ...
 
Getting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCacheGetting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCache
 
Dynamodb Presentation
Dynamodb PresentationDynamodb Presentation
Dynamodb Presentation
 
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
 
Introduction to Amazon Kinesis Firehose - AWS August Webinar Series
Introduction to Amazon Kinesis Firehose - AWS August Webinar SeriesIntroduction to Amazon Kinesis Firehose - AWS August Webinar Series
Introduction to Amazon Kinesis Firehose - AWS August Webinar Series
 
Azure Redis Cache
Azure Redis CacheAzure Redis Cache
Azure Redis Cache
 
데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...
데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...
데이터 분석가를 위한 신규 분석 서비스 - 김기영, AWS 분석 솔루션즈 아키텍트 / 변규현, 당근마켓 소프트웨어 엔지니어 :: AWS r...
 
AWS Identity, Directory, and Access Services: An Overview
AWS Identity, Directory, and Access Services: An Overview AWS Identity, Directory, and Access Services: An Overview
AWS Identity, Directory, and Access Services: An Overview
 
Elastic Load Balancing Deep Dive - AWS Online Tech Talk
Elastic  Load Balancing Deep Dive - AWS Online Tech TalkElastic  Load Balancing Deep Dive - AWS Online Tech Talk
Elastic Load Balancing Deep Dive - AWS Online Tech Talk
 
복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021
복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021
복잡한 권한신청문제 ConsoleMe로 해결하기 - 손건 (AB180) :: AWS Community Day Online 2021
 
DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환
DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환
DMS와 SCT를 활용한 Oracle에서 Open Source DB로의 전환
 
Introduction to AWS Glue
Introduction to AWS GlueIntroduction to AWS Glue
Introduction to AWS Glue
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)
 
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
 
[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기
[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기
[2019] PAYCO 쇼핑 마이크로서비스 아키텍처(MSA) 전환기
 
Amazon DynamoDB 키 디자인 패턴
Amazon DynamoDB 키 디자인 패턴Amazon DynamoDB 키 디자인 패턴
Amazon DynamoDB 키 디자인 패턴
 
Exact Microsoft AZ-900 Questions And Answers
Exact Microsoft AZ-900 Questions And AnswersExact Microsoft AZ-900 Questions And Answers
Exact Microsoft AZ-900 Questions And Answers
 

Similar to Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent 2017

Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...
Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...
Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...Amazon Web Services
 
DAT320_Moving a Galaxy into Cloud
DAT320_Moving a Galaxy into CloudDAT320_Moving a Galaxy into Cloud
DAT320_Moving a Galaxy into CloudAmazon Web Services
 
Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...
Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...
Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...Amazon Web Services
 
ABD312_Deep Dive Migrating Big Data Workloads to AWS
ABD312_Deep Dive Migrating Big Data Workloads to AWSABD312_Deep Dive Migrating Big Data Workloads to AWS
ABD312_Deep Dive Migrating Big Data Workloads to AWSAmazon Web Services
 
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...Amazon Web Services
 
Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...
Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...
Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...Amazon Web Services
 
Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...
Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...
Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...Amazon Web Services
 
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL ServicesAmazon Web Services
 
Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...
Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...
Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...Amazon Web Services
 
Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...
Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...
Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...Amazon Web Services
 
DAT316_Report from the field on Aurora PostgreSQL Performance
DAT316_Report from the field on Aurora PostgreSQL PerformanceDAT316_Report from the field on Aurora PostgreSQL Performance
DAT316_Report from the field on Aurora PostgreSQL PerformanceAmazon Web Services
 
DAT310_Which Database to Use When
DAT310_Which Database to Use WhenDAT310_Which Database to Use When
DAT310_Which Database to Use WhenAmazon Web Services
 
DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...
DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...
DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...Amazon Web Services
 
Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017
Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017
Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017Amazon Web Services
 
Migrating your traditional Data Warehouse to a Modern Data Lake
Migrating your traditional Data Warehouse to a Modern Data LakeMigrating your traditional Data Warehouse to a Modern Data Lake
Migrating your traditional Data Warehouse to a Modern Data LakeAmazon Web Services
 
Automating Big Data Technologies for Faster Time-to-Value
 Automating Big Data Technologies for Faster Time-to-Value Automating Big Data Technologies for Faster Time-to-Value
Automating Big Data Technologies for Faster Time-to-ValueAmazon Web Services
 
Architecting an Open Data Lake for the Enterprise
 Architecting an Open Data Lake for the Enterprise  Architecting an Open Data Lake for the Enterprise
Architecting an Open Data Lake for the Enterprise Amazon Web Services
 
GPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud Data
GPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud DataGPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud Data
GPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud DataAmazon Web Services
 
GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...
GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...
GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...Amazon Web Services
 
Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017
Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017
Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017Amazon Web Services
 

Similar to Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent 2017 (20)

Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...
Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...
Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:...
 
DAT320_Moving a Galaxy into Cloud
DAT320_Moving a Galaxy into CloudDAT320_Moving a Galaxy into Cloud
DAT320_Moving a Galaxy into Cloud
 
Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...
Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...
Case Study: Sprinklr Uses Amazon EBS to Maximize Its NoSQL Deployment - DAT33...
 
ABD312_Deep Dive Migrating Big Data Workloads to AWS
ABD312_Deep Dive Migrating Big Data Workloads to AWSABD312_Deep Dive Migrating Big Data Workloads to AWS
ABD312_Deep Dive Migrating Big Data Workloads to AWS
 
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
 
Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...
Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...
Amazon DynamoDB Deep Dive Advanced Design Patterns for DynamoDB (DAT401) - AW...
 
Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...
Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...
Tinder and DynamoDB: It's a Match! Massive Data Migration, Zero Down Time - D...
 
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
 
Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...
Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...
Amazon.com - Replacing 100s of Oracle DBs with Just One: DynamoDB - ARC406 - ...
 
Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...
Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...
Report from the Field on the PostgreSQL-compatible Edition of Amazon Aurora -...
 
DAT316_Report from the field on Aurora PostgreSQL Performance
DAT316_Report from the field on Aurora PostgreSQL PerformanceDAT316_Report from the field on Aurora PostgreSQL Performance
DAT316_Report from the field on Aurora PostgreSQL Performance
 
DAT310_Which Database to Use When
DAT310_Which Database to Use WhenDAT310_Which Database to Use When
DAT310_Which Database to Use When
 
DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...
DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...
DynamoDB adaptive capacity: smooth performance for chaotic workloads - DAT327...
 
Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017
Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017
Airbnb Runs on Amazon Aurora - DAT331 - re:Invent 2017
 
Migrating your traditional Data Warehouse to a Modern Data Lake
Migrating your traditional Data Warehouse to a Modern Data LakeMigrating your traditional Data Warehouse to a Modern Data Lake
Migrating your traditional Data Warehouse to a Modern Data Lake
 
Automating Big Data Technologies for Faster Time-to-Value
 Automating Big Data Technologies for Faster Time-to-Value Automating Big Data Technologies for Faster Time-to-Value
Automating Big Data Technologies for Faster Time-to-Value
 
Architecting an Open Data Lake for the Enterprise
 Architecting an Open Data Lake for the Enterprise  Architecting an Open Data Lake for the Enterprise
Architecting an Open Data Lake for the Enterprise
 
GPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud Data
GPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud DataGPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud Data
GPSTEC315_GPS Optimizing Tips Amazon Redshift for Cloud Data
 
GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...
GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...
GPS: Optimizing Tips: Amazon Redshift for Cloud Data Warehousing - GPSTEC315 ...
 
Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017
Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017
Self-Service Analytics with AWS Big Data and Tableau - ARC217 - re:Invent 2017
 

More from Amazon Web Services

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Amazon Web Services
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Amazon Web Services
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateAmazon Web Services
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSAmazon Web Services
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Amazon Web Services
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Amazon Web Services
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...Amazon Web Services
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsAmazon Web Services
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareAmazon Web Services
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSAmazon Web Services
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAmazon Web Services
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareAmazon Web Services
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWSAmazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckAmazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...Amazon Web Services
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceAmazon Web Services
 

More from Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent 2017

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Advanced Design Patterns for Amazon DynamoDB P A D M A M A L L I G A R J U N A N R E G I S G I M E N I S R I C K H O U L I H A N A W S P r o f e s s i o n a l S e r v i c e s D A T 4 0 5 N o v e m b e r 3 0 , 2 0 1 7 AWS re:INVENT
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Environment Setup (15 minute) 1. Open https://tinyurl.com/awsddbwks 2. Under “Preparation,” run Steps 1-8. 3. Stuck on Step1? Raise your hands. DAT 405 - Workshop on Advanced Design Patterns for Amazon DynamoDB Prerequisites: 1. Laptop 2. Basic understanding of DynamoDB
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Advanced Design Patterns for Amazon DynamoDB P A D M A M A L L I G A R J U N A N R E G I S G I M E N I S R I C K H O U L I H A N A W S P r o f e s s i o n a l S e r v i c e s D A T 4 0 5 N o v e m b e r 3 0 , 2 0 1 7 AWS re:INVENT
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AGENDA • Prerequisites for the workshop • Key DynamoDB concepts • Tenets of NoSQL data modeling • Workshop (2 hours, 7 labs) • Design patterns - m:n relationships, index overloading, sparse indexes, locking, adjacency lists, DynamoDB Streams
  • 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AMAZON DYNAMODB - KEY CONCEPTS Document or Key-Value Scales to Any Workload Fully Managed NoSQL Access Control Event-Driven Programming Fast and Consistent Table Items Attributes Partition Key Sort Key • Local Secondary Index • Global Secondary Index
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Selecting a Partition Key • Large number of distinct values • Values are uniformly requested, at random AMAZON DYNAMODB - KEY CONCEPTS Selecting a Sort Key • Model 1:n and m:n relationships • Query across entity types • Efficient/selective queries • Range queries Examples: • Bad: Status, Gender • Good: CustomerId, DeviceId Examples: • Orders and OrderItems per Customer
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Understand the use case • Identify the access patterns • Read/Write workloads • Query dimensions and aggregations • Data-modeling • Using NoSQL design patterns • Review -> Repeat -> Review TENETS OF DYNAMODB DATA MODELING
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Understand the use case • Identify the access patterns • Read/Write workloads • Query dimensions and aggregations • Data-modeling • Using NoSQL design patterns • Review -> Repeat -> Review • Nature of the data • OLTP / OLAP / full-text search • Relationships between the entities • What does concurrent access look like? • Time series data • Archiving needs, etc. TENETS OF DYNAMODB DATA MODELING
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Understand the use case • Identify the access patterns • Read/Write workloads • Query dimensions and aggregations • Data-modeling • Using NoSQL design patterns • Review -> Repeat -> Review • Source Data analysis (write workload) • Reading one item vs multiple items (read workload) • Query aggregations and KPIs TENETS OF DYNAMODB DATA MODELING
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Understand the use case • Identify the access patterns • Read/Write workloads • Query dimensions and aggregations • Data-modeling • Using NoSQL design patterns • Review -> Repeat -> Review TENETS OF DYNAMODB DATA MODELING • 1-1, 1-m, n-m relationships • 1 application = 1 table • Avoid unnecessary fetches • Simplify access patterns • Identify Primary Key • Partition-Key and Sort-Key • Query dimensions using LSIs and GSIs
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Understand the use case • Identify the access patterns • Read/Write workloads • Query dimensions and aggregations • Data-modeling • Using NoSQL design patterns • Review -> Repeat -> Review TENETS OF DYNAMODB DATA MODELING
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Local Secondary Index Global Secondary Index CAPACITY PLANNING FOR INDEXES • Index is local to the partition • Data size per partition <10GB • Index across partitions • Eventually consistent • Consumes RCUs/WCUs from the table’s provisioning • RCUs/WCUs are provisioned separately for GSIs If GSIs don’t have enough write capacity, table writes will be throttled!
  • 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Throughput § Provision any amount of throughput to a table Size § Add any number of items to a table - Max item size is 400 KB - LSIs limit the number of range keys due to 10 GB limit Scaling is achieved through partitioning SCALING
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. PARTITIONING MATH Number of Partitions By Capacity (Total RCU / 3000) + (Total WCU / 1000) By Size Total Size / 10 GB Total Partitions CEILING(MAX (Capacity, Size)) In the future, these details might change…
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. PARTITIONING EXAMPLE Table size = 8 GB, RCUs = 5000, WCUs = 500 RCUs per partition = 5000/3 = 1666.67 WCUs per partition = 500/3 = 166.67 Data/partition = 10/3 = 3.33 GB RCUs and WCUs are uniformly spread across partitions Number of Partitions By Capacity (5000 / 3000) + (500 / 1000) = 2.17 By Size 8 / 10 = 0.8 Total Partitions CEILING(MAX (2.17, 0.8)) = 3
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 0 400 800 1200 1600 CapacityUnits Time Provisioned Consumed “Save up” unused capacity Consume saved-up capacity Burst: 300 seconds (1200 × 300 = 360k CU) BURST CAPACITY IS BUILT-IN
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ADAPTIVE THROUGHPUT Helped over 2800 Amazon tables & indexes on Prime Day!
  • 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minutes per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts WORKSHOP
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Exercise #1 - DynamoDB Capacity Units & Partitioning (20 minutes) What you’ll learn: • Tables with lower WCUs • Write a smaller data set • Write larger data sets at high velocity • Burst capacity • Behavior when dialing up capacity • Under-provisioned WCUs on a GSI • Viewing these metrics on Cloudwatch WORKSHOP AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DYNAMODB SCAN OPERATIONS • Access every item in a table on an index • Read 1MB data in each operation • Use LastEvaluatedKey to continue.. • Reads up to the max throughput of a single partition • Parallel scans vs Sequential scans
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. PARALLEL SCAN • Read all the items of a table faster • Take advantage of the table’s provisioned capacity • Set TotalSegments = number of application workers, each worker scans a different segment All Data items Segment 0 Segment 1 Segment 2 Worker-0 Worker-1 Worker-2 Application - Main thread Worker-3 Segment 3
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. The upcoming lab… Scenario: Scan Server logs data for response code = OK • Sequential Scan fe = "responsecode <> :f" eav = {":f": 200} response = table.scan( FilterExpression=fe, ExpressionAttributeValues=eav, Limit=pageSize ) • Parallel Scan fe = "responsecode <> :f" eav = {":f": 200} response = table.scan( FilterExpression=fe, ExpressionAttributeValues=eav, Limit=pageSize, TotalSegments=totalsegments, Segment=threadsegment )
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich Exercise #2 – DynamoDB scans – Sequential & Parallel table scan (10 minutes) What you’ll learn: • Time a sequential (simple) scan vs a parallel scan. • Populate a table with a large data set. • Scan and compare run times. • Time difference will be significant for larger data sets. • Don’t forget to review the Python scripts! WORKSHOP WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: GSI OVERLOADING • Working with the 5 GSIs limitation • Overload attribute values based on an item’s context Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales (5) Current Job role (6) Employees in a City (7) Warehouse Location (8) Employee ID …. and many more
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: GSI OVERLOADING Example: Query Employee Database by (1) Employee Name (2) Warehouse (3) Hire Date (4) Quarterly Sales Partition Key = “Employee ID” Sort Key = (Let’s look at final design) DynamoDB Table design…
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: GSI OVERLOADING Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales DATA MODELING: GSI OVERLOADING
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales DATA MODELING: GSI OVERLOADING
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales DATA MODELING: GSI OVERLOADING
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales DATA MODELING: GSI OVERLOADING
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales DATA MODELING: GSI OVERLOADING
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales DATA MODELING: GSI OVERLOADING Partition Key = “Employee ID” Sort Key = Use a generic attribute-name “A” Value is based on the item type. Create a GSI on “A”.
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 37. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 38. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Exercise #3 – GSI Overloading (15 minute) What you’ll learn: • Load the Employee data, create an overloaded-GSI, and query the results! WORKSHOP AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 39. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: SPARSE INDEXES • Saves WCUs • Selective querying Example: Investigators use a GSI to query “Assigned” Cases A U D I T S Primary Key Attributes CaseID Item CASE1 DETAILS1 Assignee Tags ASIN OrderID INV1 Assignee Metadata INV1#AUDIT1 Assignee Status_Date Type TicketID ASSIGNED_2017-08-08 T1 INV1#AUDIT2 Assignee Status_Date Type TicketID COMPLETED_2017-08-08 T1 INV1#AUDIT3 Assignee Status_Date Type TicketID POST-AUDIT_2017-08-08 T1 INV1#AUDIT4 Assignee Status_Date Type TicketID ARCHIVED_2017-08-08 T1 S31 S3Datapoints
  • 40. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: SPARSE INDEXES Example: Investigators use a GSI to query “Assigned” Cases A U D I T S Primary Key Attributes CaseID Item CASE1 DETAILS1 Other attributes INV1 Other attributes INV1#AUDIT1 ASSIGNEE STATUS_DATE ASSIGNED_2017-08-08 T1 INV1#AUDIT2 ASSIGNEE STATUS_DATE COMPLETED_2017-08-08 T1 INV1#AUDIT3 ASSIGNEE STATUS_DATE POST-AUDIT_2017-08-08 T1 INV1#AUDIT4 ASSIGNEE STATUS_DATE ARCHIVED_2017-08-08 T1
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: SPARSE INDEXES Example: Investigators use a GSI to query “Assigned” Cases A U D I T S Primary Key Attributes CaseID Item CASE1 DETAILS1 Other attributes INV1 Other attributes INV1#AUDIT1 ASSIGNEE (GSI-PK) STATUS_DATE (GSI-SK) ASSIGNED_2017-08-08 T1 INV1#AUDIT2 ASSIGNEE (GSI-PK) STATUS_DATE (GSI-SK) COMPLETED_2017-08-08 T1 INV1#AUDIT3 ASSIGNEE (GSI-PK) STATUS_DATE (GSI-SK) POST-AUDIT_2017-08-08 T1 INV1#AUDIT4 ASSIGNEE (GSI-PK) STATUS_DATE (GSI-SK) ARCHIVED_2017-08-08 T1
  • 42. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: SPARSE INDEXES Example: Investigators use a GSI to query “Assigned” Cases A U D I T S Primary Key Attributes CaseID Item CASE1 DETAILS1 Other attributes INV1 Other attributes INV1#AUDIT1 ASSIGNEE GSI_STATUS_DATE Status_Date ASSIGNED_2017-08-08 T1 ASSIGNED_2017-08-08 T1 INV1#AUDIT2 Assignee Status_Date COMPLETED_2017-08-08 T1 INV1#AUDIT3 Assignee Status_Date POST-AUDIT_2017-08-08 T1 INV1#AUDIT4 Assignee Status_Date ARCHIVED_2017-08-08 T1
  • 43. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: SPARSE INDEXES – ANOTHER EXAMPLE Id (Partition) User Game Score Date Award 1 Bob G1 1300 2012-12-23 2 Bob G1 1450 2012-12-23 3 Jay G1 1600 2012-12-24 4 Mary G1 2000 2012-10-24 Champ 5 Ryan G2 123 2012-03-10 6 Jones G2 345 2012-03-20 Game-scores-table Award (Partition) Id User Score Champ 4 Mary 2000 Award-GSI Scan sparse GSIs
  • 44. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 45. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Exercise #4 – Sparse Indexes (15 minute) What you’ll learn: • Create a GSI on an existing table (this step takes a few minutes) • Review the use case for using a sparse index • Take advantage of sparse Indexes! WORKSHOP AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 46. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS • Define hierarchical relationships • Execute selective queries
  • 47. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS Multivalue sorts and filters 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 Partition key Sort key
  • 48. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS Approach 1 : Query Filter 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 SELECT * FROM Game WHERE Opponent='Bob' ORDER BY Date DESC FILTER ON Status='PENDING' Bob (filtered out)
  • 49. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS Approach 2 : Composite Sort Keys StatusDate DONE_2014-10-02 IN_PROGRESS_2014-10-08 IN_PROGRESS_2014-10-03 PENDING_2014-09-30 PENDING_2014-10-03 Status DONE IN_PROGRESS IN_PROGRESS PENDING PENDING Date 2014-10-02 2014-10-08 2014-10-03 2014-10-03 2014-09-30 + =
  • 50. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS Approach 2 : Composite Sort Keys 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 Partition key Sort key
  • 51. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS Approach 2 : Composite Sort Keys 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 BEGINS_WITH 'PENDING'
  • 52. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS • Define hierarchical relationships • Execute selective queries Example: Query Amazon buildings by Country, State, City, Office Location Partition Key = “USA” Sort Key = “TX”CONCAT ( , “AUSTIN”, “AUS-007” )
  • 53. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS • Define hierarchical relationships • Execute selective queries Example: Query Amazon buildings by State, City, Office Location
  • 54. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: COMPOSITE SORT KEYS • Use composite sort key to define a hierarchy • Highly selective queries with sort conditions • Reduce query complexity
  • 55. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 56. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 57. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Exercise #5 – Composite Sort Keys (15 minute) What you’ll learn: • Query Employees data using State, City, Department. • Create a GSI on PartitionKey=State; SortKey=City#Dept. • If the attribute doesn’t exist, you have to add it to the table. • Recap: In the real world, understand all the access patterns to design your table WORKSHOP AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 58. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: ADJACENCY LISTS • Easily model many-to-many relationships • Without excessive data duplication Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID
  • 59. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: ADJACENCY LISTS Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID Primary Key Attributes ID Item INVOICE1 INVOICE1 Other Invoice Attributes BILL1 Bill-Invoice Attributes BILL2 Bill-Invoice Attributes BILL1 BILL1 Other Bill Attributes BILL2 BILL1 Other Bill Attributes
  • 60. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: ADJACENCY LISTS Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID Primary Key Attributes ID Item INVOICE1 INVOICE1 Other Invoice Attributes BILL1 Bill-Invoice Attributes BILL2 Bill-Invoice Attributes BILL1 BILL1 Other Bill Attributes BILL2 BILL1 Other Bill Attributes
  • 61. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: ADJACENCY LISTS Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID Primary Key Attributes ID Item (GSI-PK) INVOICE1 INVOICE1 Other Invoice Attributes BILL1 Bill-Invoice Attributes BILL2 Bill-Invoice Attributes BILL1 BILL1 Other Bill Attributes BILL2 BILL2 Other Bill Attributes
  • 62. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: ADJACENCY LISTS Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID GSI Primary Key Projected Attributes Item INVOICE1 ID Item Other Invoice Attributes INVOICE1 INVOICE1 BILL1 ID Item Bill-Invoice Attributes INVOICE1 BILL1 ID Item Other Bill Attributes BILL1 BILL1 BILL2 ID Item Bill-Invoice Attributes INVOICE1 BILL2 ID Item Other Bill Attributes BILL2 BILL2 Secondary index
  • 63. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: LOCKING Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID (3,) Modify an invoice within a transaction Primary Key Attributes ID Item INVOICE1 INVOICE1 Other Invoice Attributes BILL1 Bill-Invoice Attributes BILL2 Bill-Invoice Attributes BILL1 BILL1 Other Bill Attributes BILL2 BILL1 Other Bill Attributes
  • 64. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: LOCKING Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID (3,) Modify an invoice within a transaction Primary Key Attributes ID Item INVOICE1 INVOICE1 LOCK Other Invoice Attributes 0/1 BILL1 Bill-Invoice Attributes BILL2 Bill-Invoice Attributes BILL1 BILL1 Other Bill Attributes BILL2 BILL1 Other Bill Attributes
  • 65. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: VERSIONING Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID (3,) Modify an invoice within a transaction (4,) Versioning (history of Invoice updates) Primary Key Attributes ID Item INVOICE1 v0-INVOICE1 LOCK Other Invoice Attributes 0/1 v1-INVOICE1 Other Invoice Attributes
  • 66. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: VERSIONING Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID (3,) Modify an invoice within a transaction (4,) Versioning (history of Invoice updates) Primary Key Attributes ID Item INVOICE1 v0-INVOICE1 LOCK Other Invoice Attributes 0/1 v1-INVOICE1 Other Invoice Attributes
  • 67. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: VERSIONING Example: An invoice contains many bills. A bill can be broken up into multiple invoices. Desired access patterns: (1,) Get Bills by InvoiceID (2,) Get invoices by BillID (3,) Modify an invoice within a transaction (4,) Versioning (history of Invoice updates) Primary Key Attributes ID Item INVOICE1 v0-INVOICE1 LOCK Other Invoice Attributes 0/1 v1-INVOICE1 Other Invoice Attributes v2-INVOICE1 Other Invoice Attributes
  • 68. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DATA MODELING: VERSIONING Primary Key Attributes ID Item INVOICE1 v0-INVOICE1 LOCK Other Invoice Attributes 0/1 v0-BILL1 Bill-Invoice Attributes v0-BILL2 Bill-Invoice Attributes v1-INVOICE1 Other Invoice Attributes v1-BILL1 Bill-Invoice Attributes v2-INVOICE1 Other Invoice Attributes v2-BILL1 Bill-Invoice Attributes v2-BILL2 Bill-Invoice Attributes BILL1 v0-BILL1 Other Bill Attributes
  • 69. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 70. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. In the upcoming lab…
  • 71. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Exercise #6 – Locking (10 minute) What you’ll learn: • Lock an employee record, and prevent dirty writes. • After successful obtaining a lock, make the changes, then release the lock. • Recap: In the real-world, understand all the access patterns to design your table WORKSHOP AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 72. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DYNAMODB STREAMS AND AWS LAMBDA
  • 73. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DYNAMODB STREAMS AS TRIGGERS Lambda function Notify change Item/Table Level Metrics Amazon CloudSearch Kinesis Firehose
  • 74. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Exercise #7 – DynamoDB Streams & Lambda (10 minutes) What you’ll learn: • Build a replication workflow • Enable Streams on the tlog table • Create a replication target • Create a Lambda function (with IAM policies) to read the streams and write to the target WORKSHOP AWS STAFF IN THE ROOM • Rick Houlihan • Regis Gimenis • Sean Shriver • Edin Zulich WORKSHOP STRUCTURE • 7 Labs • ~15 minute per Lab • Raise your hands for questions • Staying in sync with the group • Review the Python scripts
  • 75. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. D A T 4 0 5 – A d v a n c e d D e s i g n P a t t e r n s f o r A m a z o n D y n a m o D B P A D M A M A L L I G A R J U N A N * R E G I S G I M E N I S * R I C K H O U L I H A N thank you! Please fill out the evaluations :)