SlideShare ist ein Scribd-Unternehmen logo
1 von 81
Downloaden Sie, um offline zu lesen
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Advanced Design Patterns for
Amazon DynamoDB – Workshop
Padma Malligarjunan
Senior Product Manager, AWS
D A T 4 0 4
Sean Shriver
Senior Solutions Architect, AWS
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Set up the lab environment
1. Prerequisites: Laptop, Amazon DynamoDB basics
2. Setup time: 15 minutes
3. Go to https://amazon.qwiklabs.com
4. Choose Sign In and log on using your credentials or click Join Here to create a new
account.
1. If you click on Create New Account or the Forgot Password link, you will
receive an email from noreply@qwiklabs.com.
5. Enter in the top Search bar ”Advanced Design Patterns Using Amazon
DynamoDB”. Click on the lab to open it.
6. Click Start Lab. Enter the Lab Access Code provided to you.
7. On the right-side of the page is the outline for the lab. Note that there are 8 exercises
8. Review and complete the “Setup” and “Start Lab” sections.
9. Stop when you see the “You have Completed the Setup!” and wait. Do not start
Exercise 1.
© 2018, 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 exercises)
• Design patterns - m:n relationships, index overloading, sparse
indexes, adjacency lists, Amazon DynamoDB Streams
© 2018, 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
• Global secondary index
• Local secondary index
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon DynamoDB – Key concepts
Selecting a Partition Key
• Large number of distinct
values
• Requests are uniformly
distributed
Examples
• Bad: Status, Year
• Good: CustomerId, DeviceId
Selecting a Sort Key
• Model 1:n and m:n
relationships
• Used to order data on disk
• Efficient/selective queries
• Range queries
Examples
• OrderId and OrderItemId per
CustomerId
© 2018, 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
© 2018, 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
© 2018, 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 versus
multiple items (read workload)
• Query aggregations and KPIs
Tenets of DynamoDB data modeling
© 2018, 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:n, m:n 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
© 2018, 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
© 2018, 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, all table writes will be
throttled!
© 2018, 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
• Tables can scale to any size
• Max item size is 400 KB
Scaling is achieved through partitioning
Horizontal scaling
© 2018, 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive capacity
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive capacity
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive capacity
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive capacity
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive capacity
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive capacity
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
• Calculate provisioned throughput for all access patterns to be
supported by the table & secondary indexes
• Design the table for uniform access across a large number of
logical partition keys
• The key pressure for each logical partition key should be
under 3,000 RCUs and 1,000 WCUs.
• Enable DynamoDB auto scaling for normal traffic
• Understand planning for marketing events or Prime Day type
activities
Capacity planning guidelines
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Workshop plan
1. Seven exercises, skipping exercise #2
2. ~15 minutes per exercise
3. Raise your hands for questions
4. Stay in sync with the class
5. Review the Python scripts
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #1 - DynamoDB Capacity Units & Partitioning (20 minutes)
What you’ll learn:
• Tables with a small number of WCUs
• Write a smaller data set
• Write larger data sets at a higher rate
• Burst capacity
• Behavior when increasing provisioned capacity
• Under-provisioned WCUs on a GSI
• Viewing these metrics on Amazon CloudWatch
Workshop
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
DynamoDB Scan operations
• Access every item in a table on an index
• Read 1 MB data in each operation
• Use LastEvaluatedKey to continue
• Reads up to the maximum throughput of a single partition
• Parallel scans versus sequential scans
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Parallel Scan
• Read all the items from 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Sequential versus parallel Scan
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
)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Sequential versus parallel Scan
Scenario:
Scan server logs data for response code = OK
• Sequential Scan
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Sequential versus Parallel Scan
Scenario:
Scan server logs data for response code = OK
• Parallel Scan
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #2 – DynamoDB Sequential and Parallel table scan (10 minutes)
What you’ll learn
• Time a Sequential (simple) scan versus 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Write sharding – Voting example
Partition 1
1000 WCUs
Partition K
1000 WCUs
Partition M
1000 WCUs
Partition N
1000 WCUs
Votes Table
Candidate A Candidate B
Voters
Provision 200,000 WCUs
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Write sharding – Scaling writes
Candidate A_2
Candidate B_1
Candidate B_2
Candidate B_3
Candidate B_5
Candidate B_4
Candidate B_7
Candidate B_6
Candidate A_1
Candidate A_3
Candidate A_4
Candidate A_7 Candidate B_8
Candidate A_6 Candidate A_8
Candidate A_5
Voter
Votes Table
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Write sharding – Scaling writes
Candidate A_2
Candidate B_1
Candidate B_2
Candidate B_3
Candidate B_5
Candidate B_4
Candidate B_7
Candidate B_6
Candidate A_1
Candidate A_3
Candidate A_4
Candidate A_7 Candidate B_8
UpdateItem: “CandidateA_” + rand(0, 10)
ADD 1 to Votes
Candidate A_6 Candidate A_8
Candidate A_5
Voter
Votes Table
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Write sharding – Merging results
Votes Table
Candidate A_2
Candidate B_1
Candidate B_2
Candidate B_3
Candidate B_5
Candidate B_4
Candidate B_7
Candidate B_6
Candidate A_1
Candidate A_3
Candidate A_4
Candidate A_5
Candidate A_6 Candidate A_8
Candidate A_7 Candidate B_8
Periodic
Process
Candidate A
Total: 2.5M
1. Sum
2. Store Voter
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Write sharding – Trade-in orders
ShipmentService
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #3 – GSI Write Sharding (15 minute)
What you’ll learn:
• Use the same server logs data from the previous lab, and query the selected
list of 404 error records
• The GSI was already created, review the GSI definition
• Query the GSI to retrieve the records selectively, also include sort key
• Review the Python scripts
Workshop
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data modeling: GSI overloading
• Working with the 5 GSI default limit
• Overload attribute values based on an item’s context
Example: Query Employee Database by
(1) Employee Name (5) Current Job role
(2) Desk (6) Employees in a City
(3) Hire Date (7) Warehouse Location
(4) Quarterly Sales (8) Employee ID
…. and many more
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data modeling: GSI overloading
Partition Key = “Employee ID”
Sort Key = (Let’s look at final design)
DynamoDB Table design…
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
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”.
Example: Query Employee Database by
(1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #4 – GSI Key Overloading (15 minute)
What you’ll learn:
• Load the Employee data, create an overloaded-GSI, and query the results!
Workshop
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #5 – 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data modeling: Composite sort keys
• Define hierarchical relationships
• Execute selective queries
© 2018, 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
© 2018, 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)
© 2018, 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
+ =
© 2018, 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
© 2018, 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'
© 2018, 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” )
© 2018, 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
© 2018, 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
In the upcoming lab…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #6 – Composite keys (15 minute)
What you’ll learn:
• Query employee 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
© 2018, 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 invoice ID
(2) Get invoices by bill ID
© 2018, 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 invoice ID, (2) Get invoices by bill ID
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
© 2018, 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 invoice ID, (2) Get invoices by bill ID
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
© 2018, 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 invoice ID, (2) Get invoices by bill ID
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
© 2018, 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 invoice ID, (2) Get invoices by bill ID
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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #7 – Adjacency Lists (10 minute)
What you’ll learn:
• Many-to-many relationships between Invoices, Bills & Customers using
Adjacency lists and an overloaded GSI partition key.
• Query all Bills for an Invoice
• Query all invoices for a Bill.
Workshop
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
DynamoDB Streams and AWS Lambda
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
DynamoDB Streams as triggers
Lambda function
Notify change
Item/Table Level Metrics
Amazon CloudSearch
Amazon Kinesis Firehose
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
DynamoDB Streams
N e a r - r e a l - t i m e m e t r i c s a n d a g g r e g a t i o n s
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Exercise #8 – 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 AWS Identity and Access Management
[IAM] policies) to read the streams and write to the target
Workshop
Thank you!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Padma Malligarjunan - @theRealPadma
Sean Shriver - @sean_shriver
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Weitere ähnliche Inhalte

Was ist angesagt?

Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...
Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...
Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...Amazon Web Services
 
Visualization with Amazon QuickSight
Visualization with Amazon QuickSightVisualization with Amazon QuickSight
Visualization with Amazon QuickSightAmazon Web Services
 
How to Choose The Right Database on AWS - Berlin Summit - 2019
How to Choose The Right Database on AWS - Berlin Summit - 2019How to Choose The Right Database on AWS - Berlin Summit - 2019
How to Choose The Right Database on AWS - Berlin Summit - 2019Randall Hunt
 
Best Practices for Encrypting Data on AWS
Best Practices for Encrypting Data on AWSBest Practices for Encrypting Data on AWS
Best Practices for Encrypting Data on AWSAmazon Web Services
 
Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...
Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...
Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...Amazon Web Services
 
민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS
민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS
민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWSAmazon Web Services Korea
 
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Amazon Web Services
 
AWS EMR Cost optimization
AWS EMR Cost optimizationAWS EMR Cost optimization
AWS EMR Cost optimizationSANG WON PARK
 
Best Practices in the Use of Columnar Databases
Best Practices in the Use of Columnar DatabasesBest Practices in the Use of Columnar Databases
Best Practices in the Use of Columnar DatabasesDATAVERSITY
 
아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...
아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...
아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...Amazon Web Services Korea
 
Amazon RDS: Deep Dive - SRV310 - Chicago AWS Summit
Amazon RDS: Deep Dive - SRV310 - Chicago AWS SummitAmazon RDS: Deep Dive - SRV310 - Chicago AWS Summit
Amazon RDS: Deep Dive - SRV310 - Chicago AWS SummitAmazon Web Services
 
대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...
대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...
대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...Amazon Web Services Korea
 
Mainframe Modernization with AWS: Patterns and Best Practices
Mainframe Modernization with AWS: Patterns and Best PracticesMainframe Modernization with AWS: Patterns and Best Practices
Mainframe Modernization with AWS: Patterns and Best PracticesAmazon Web Services
 
Building a modern data platform in AWS
Building a modern data platform in AWSBuilding a modern data platform in AWS
Building a modern data platform in AWSAmazon Web Services
 
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...Amazon Web Services
 
AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...
AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...
AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...Amazon Web Services
 
AWS Governance at Scale_AWSPSSummit_Singapore
AWS Governance at Scale_AWSPSSummit_SingaporeAWS Governance at Scale_AWSPSSummit_Singapore
AWS Governance at Scale_AWSPSSummit_SingaporeAmazon Web Services
 

Was ist angesagt? (20)

Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...
Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...
Big Data Analytics Architectural Patterns and Best Practices (ANT201-R1) - AW...
 
Visualization with Amazon QuickSight
Visualization with Amazon QuickSightVisualization with Amazon QuickSight
Visualization with Amazon QuickSight
 
Building-a-Data-Lake-on-AWS
Building-a-Data-Lake-on-AWSBuilding-a-Data-Lake-on-AWS
Building-a-Data-Lake-on-AWS
 
How to Choose The Right Database on AWS - Berlin Summit - 2019
How to Choose The Right Database on AWS - Berlin Summit - 2019How to Choose The Right Database on AWS - Berlin Summit - 2019
How to Choose The Right Database on AWS - Berlin Summit - 2019
 
Best Practices for Encrypting Data on AWS
Best Practices for Encrypting Data on AWSBest Practices for Encrypting Data on AWS
Best Practices for Encrypting Data on AWS
 
2020.02.06 우리는 왜 glue를 버렸나?
2020.02.06 우리는 왜 glue를 버렸나?2020.02.06 우리는 왜 glue를 버렸나?
2020.02.06 우리는 왜 glue를 버렸나?
 
Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...
Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...
Migrate Your Hadoop/Spark Workload to Amazon EMR and Architect It for Securit...
 
민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS
민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS
민첩하고 비용효율적인 Data Lake 구축 - 문종민 솔루션즈 아키텍트, AWS
 
Digital Transformation with Microsoft Azure
Digital Transformation with Microsoft AzureDigital Transformation with Microsoft Azure
Digital Transformation with Microsoft Azure
 
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
 
AWS EMR Cost optimization
AWS EMR Cost optimizationAWS EMR Cost optimization
AWS EMR Cost optimization
 
Best Practices in the Use of Columnar Databases
Best Practices in the Use of Columnar DatabasesBest Practices in the Use of Columnar Databases
Best Practices in the Use of Columnar Databases
 
아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...
아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...
아름답고 유연한 데이터 파이프라인 구축을 위한 Amazon Managed Workflow for Apache Airflow - 유다니엘 A...
 
Amazon RDS: Deep Dive - SRV310 - Chicago AWS Summit
Amazon RDS: Deep Dive - SRV310 - Chicago AWS SummitAmazon RDS: Deep Dive - SRV310 - Chicago AWS Summit
Amazon RDS: Deep Dive - SRV310 - Chicago AWS Summit
 
대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...
대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...
대규모 온프레미스 하둡 마이그레이션을 위한 실행 전략과 최적화 방안 소개-유철민, AWS Data Architect / 박성열,AWS Pr...
 
Mainframe Modernization with AWS: Patterns and Best Practices
Mainframe Modernization with AWS: Patterns and Best PracticesMainframe Modernization with AWS: Patterns and Best Practices
Mainframe Modernization with AWS: Patterns and Best Practices
 
Building a modern data platform in AWS
Building a modern data platform in AWSBuilding a modern data platform in AWS
Building a modern data platform in AWS
 
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
 
AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...
AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...
AWS Storage Services - AWS Presentation - AWS Cloud Storage for the Enterpris...
 
AWS Governance at Scale_AWSPSSummit_Singapore
AWS Governance at Scale_AWSPSSummit_SingaporeAWS Governance at Scale_AWSPSSummit_Singapore
AWS Governance at Scale_AWSPSSummit_Singapore
 

Ähnlich wie Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:Invent 2018

Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...
Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...
Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...Amazon Web Services
 
Module 4 - AWSome Day Online Conference 2018
Module 4 - AWSome Day Online Conference 2018Module 4 - AWSome Day Online Conference 2018
Module 4 - AWSome Day Online Conference 2018Amazon Web Services
 
DynamoDB & DAX: Database Week San Francisco
DynamoDB & DAX: Database Week San FranciscoDynamoDB & DAX: Database Week San Francisco
DynamoDB & DAX: Database Week San FranciscoAmazon Web Services
 
Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018
Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018
Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018Amazon 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
 
Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...
Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...
Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...Amazon Web Services
 
DynamoDB & DAX: Database Week SF
DynamoDB & DAX: Database Week SFDynamoDB & DAX: Database Week SF
DynamoDB & DAX: Database Week SFAmazon Web Services
 
Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)
Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)
Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)Amazon Web Services
 
Choosing the Right Database for My Workload: Purpose-Built Databases
Choosing the Right Database for My Workload: Purpose-Built Databases Choosing the Right Database for My Workload: Purpose-Built Databases
Choosing the Right Database for My Workload: Purpose-Built Databases AWS Germany
 
Workshop: Architecting a Serverless Data Lake
Workshop: Architecting a Serverless Data LakeWorkshop: Architecting a Serverless Data Lake
Workshop: Architecting a Serverless Data LakeAmazon Web Services
 
Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...
Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...
Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...Amazon Web Services
 
DynamoDB and Dax - Miguel Cervantes
DynamoDB and Dax - Miguel CervantesDynamoDB and Dax - Miguel Cervantes
DynamoDB and Dax - Miguel CervantesAmazon Web Services
 
Modernise your Data Warehouse with Amazon Redshift and Amazon Redshift Spectrum
Modernise your Data Warehouse with Amazon Redshift and Amazon Redshift SpectrumModernise your Data Warehouse with Amazon Redshift and Amazon Redshift Spectrum
Modernise your Data Warehouse with Amazon Redshift and Amazon Redshift SpectrumAmazon Web Services
 
Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...
Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...
Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...Amazon Web Services
 
Which Database is Right for My Workload?: Database Week San Francisco
Which Database is Right for My Workload?: Database Week San FranciscoWhich Database is Right for My Workload?: Database Week San Francisco
Which Database is Right for My Workload?: Database Week San FranciscoAmazon Web Services
 
Which Database is Right for My Workload?
Which Database is Right for My Workload?Which Database is Right for My Workload?
Which Database is Right for My Workload?Amazon Web Services
 
Which Database is Right for My Workload: Database Week SF
Which Database is Right for My Workload: Database Week SFWhich Database is Right for My Workload: Database Week SF
Which Database is Right for My Workload: Database Week SFAmazon Web Services
 
Optimising your Amazon Redshift Cluster for Peak Performance
Optimising your Amazon Redshift Cluster for Peak PerformanceOptimising your Amazon Redshift Cluster for Peak Performance
Optimising your Amazon Redshift Cluster for Peak PerformanceAmazon Web Services
 

Ähnlich wie Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:Invent 2018 (20)

Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...
Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...
Workshop on Advanced Design Patterns for Amazon DynamoDB - DAT405 - re:Invent...
 
Module 4 - AWSome Day Online Conference 2018
Module 4 - AWSome Day Online Conference 2018Module 4 - AWSome Day Online Conference 2018
Module 4 - AWSome Day Online Conference 2018
 
DynamoDB and DAX | AWS Floor28
DynamoDB and DAX | AWS Floor28DynamoDB and DAX | AWS Floor28
DynamoDB and DAX | AWS Floor28
 
DynamoDB & DAX: Database Week San Francisco
DynamoDB & DAX: Database Week San FranciscoDynamoDB & DAX: Database Week San Francisco
DynamoDB & DAX: Database Week San Francisco
 
Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018
Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018
Build Your First Big Data Application on AWS (ANT213-R1) - AWS re:Invent 2018
 
DAT320_Moving a Galaxy into Cloud
DAT320_Moving a Galaxy into CloudDAT320_Moving a Galaxy into Cloud
DAT320_Moving a Galaxy into Cloud
 
Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...
Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...
Get the Most out of Your Amazon Elasticsearch Service Domain (ANT334-R1) - AW...
 
DynamoDB & DAX: Database Week SF
DynamoDB & DAX: Database Week SFDynamoDB & DAX: Database Week SF
DynamoDB & DAX: Database Week SF
 
Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)
Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)
Amazon Redshift 與 Amazon Redshift Spectrum 幫您建立現代化資料倉儲 (Level 300)
 
Choosing the Right Database for My Workload: Purpose-Built Databases
Choosing the Right Database for My Workload: Purpose-Built Databases Choosing the Right Database for My Workload: Purpose-Built Databases
Choosing the Right Database for My Workload: Purpose-Built Databases
 
Workshop: Architecting a Serverless Data Lake
Workshop: Architecting a Serverless Data LakeWorkshop: Architecting a Serverless Data Lake
Workshop: Architecting a Serverless Data Lake
 
Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...
Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...
Optimizing Your Amazon Redshift Cluster for Peak Performance - AWS Summit Syd...
 
DynamoDB & DAX
DynamoDB & DAXDynamoDB & DAX
DynamoDB & DAX
 
DynamoDB and Dax - Miguel Cervantes
DynamoDB and Dax - Miguel CervantesDynamoDB and Dax - Miguel Cervantes
DynamoDB and Dax - Miguel Cervantes
 
Modernise your Data Warehouse with Amazon Redshift and Amazon Redshift Spectrum
Modernise your Data Warehouse with Amazon Redshift and Amazon Redshift SpectrumModernise your Data Warehouse with Amazon Redshift and Amazon Redshift Spectrum
Modernise your Data Warehouse with Amazon Redshift and Amazon Redshift Spectrum
 
Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...
Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...
Integrating Amazon Elasticsearch with your DevOps Tooling - AWS Online Tech T...
 
Which Database is Right for My Workload?: Database Week San Francisco
Which Database is Right for My Workload?: Database Week San FranciscoWhich Database is Right for My Workload?: Database Week San Francisco
Which Database is Right for My Workload?: Database Week San Francisco
 
Which Database is Right for My Workload?
Which Database is Right for My Workload?Which Database is Right for My Workload?
Which Database is Right for My Workload?
 
Which Database is Right for My Workload: Database Week SF
Which Database is Right for My Workload: Database Week SFWhich Database is Right for My Workload: Database Week SF
Which Database is Right for My Workload: Database Week SF
 
Optimising your Amazon Redshift Cluster for Peak Performance
Optimising your Amazon Redshift Cluster for Peak PerformanceOptimising your Amazon Redshift Cluster for Peak Performance
Optimising your Amazon Redshift Cluster for Peak Performance
 

Mehr von 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
 

Mehr von 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
 

Advanced Design Patterns for Amazon DynamoDB - Workshop (DAT404-R1) - AWS re:Invent 2018

  • 1.
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Advanced Design Patterns for Amazon DynamoDB – Workshop Padma Malligarjunan Senior Product Manager, AWS D A T 4 0 4 Sean Shriver Senior Solutions Architect, AWS
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Set up the lab environment 1. Prerequisites: Laptop, Amazon DynamoDB basics 2. Setup time: 15 minutes 3. Go to https://amazon.qwiklabs.com 4. Choose Sign In and log on using your credentials or click Join Here to create a new account. 1. If you click on Create New Account or the Forgot Password link, you will receive an email from noreply@qwiklabs.com. 5. Enter in the top Search bar ”Advanced Design Patterns Using Amazon DynamoDB”. Click on the lab to open it. 6. Click Start Lab. Enter the Lab Access Code provided to you. 7. On the right-side of the page is the outline for the lab. Note that there are 8 exercises 8. Review and complete the “Setup” and “Start Lab” sections. 9. Stop when you see the “You have Completed the Setup!” and wait. Do not start Exercise 1.
  • 4. © 2018, 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 exercises) • Design patterns - m:n relationships, index overloading, sparse indexes, adjacency lists, Amazon DynamoDB Streams
  • 5. © 2018, 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 • Global secondary index • Local secondary index
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon DynamoDB – Key concepts Selecting a Partition Key • Large number of distinct values • Requests are uniformly distributed Examples • Bad: Status, Year • Good: CustomerId, DeviceId Selecting a Sort Key • Model 1:n and m:n relationships • Used to order data on disk • Efficient/selective queries • Range queries Examples • OrderId and OrderItemId per CustomerId
  • 7. © 2018, 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. © 2018, 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. © 2018, 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 versus multiple items (read workload) • Query aggregations and KPIs Tenets of DynamoDB data modeling
  • 10. © 2018, 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:n, m:n 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. © 2018, 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. © 2018, 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, all table writes will be throttled!
  • 13. © 2018, 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 • Tables can scale to any size • Max item size is 400 KB Scaling is achieved through partitioning Horizontal scaling
  • 14. © 2018, 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
  • 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive capacity
  • 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive capacity
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive capacity
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive capacity
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive capacity
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive capacity
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. • Calculate provisioned throughput for all access patterns to be supported by the table & secondary indexes • Design the table for uniform access across a large number of logical partition keys • The key pressure for each logical partition key should be under 3,000 RCUs and 1,000 WCUs. • Enable DynamoDB auto scaling for normal traffic • Understand planning for marketing events or Prime Day type activities Capacity planning guidelines
  • 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Workshop plan 1. Seven exercises, skipping exercise #2 2. ~15 minutes per exercise 3. Raise your hands for questions 4. Stay in sync with the class 5. Review the Python scripts
  • 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #1 - DynamoDB Capacity Units & Partitioning (20 minutes) What you’ll learn: • Tables with a small number of WCUs • Write a smaller data set • Write larger data sets at a higher rate • Burst capacity • Behavior when increasing provisioned capacity • Under-provisioned WCUs on a GSI • Viewing these metrics on Amazon CloudWatch Workshop
  • 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. DynamoDB Scan operations • Access every item in a table on an index • Read 1 MB data in each operation • Use LastEvaluatedKey to continue • Reads up to the maximum throughput of a single partition • Parallel scans versus sequential scans
  • 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Parallel Scan • Read all the items from 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
  • 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Sequential versus parallel Scan 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 )
  • 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Sequential versus parallel Scan Scenario: Scan server logs data for response code = OK • Sequential Scan
  • 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Sequential versus Parallel Scan Scenario: Scan server logs data for response code = OK • Parallel Scan
  • 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #2 – DynamoDB Sequential and Parallel table scan (10 minutes) What you’ll learn • Time a Sequential (simple) scan versus 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
  • 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Write sharding – Voting example Partition 1 1000 WCUs Partition K 1000 WCUs Partition M 1000 WCUs Partition N 1000 WCUs Votes Table Candidate A Candidate B Voters Provision 200,000 WCUs
  • 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Write sharding – Scaling writes Candidate A_2 Candidate B_1 Candidate B_2 Candidate B_3 Candidate B_5 Candidate B_4 Candidate B_7 Candidate B_6 Candidate A_1 Candidate A_3 Candidate A_4 Candidate A_7 Candidate B_8 Candidate A_6 Candidate A_8 Candidate A_5 Voter Votes Table
  • 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Write sharding – Scaling writes Candidate A_2 Candidate B_1 Candidate B_2 Candidate B_3 Candidate B_5 Candidate B_4 Candidate B_7 Candidate B_6 Candidate A_1 Candidate A_3 Candidate A_4 Candidate A_7 Candidate B_8 UpdateItem: “CandidateA_” + rand(0, 10) ADD 1 to Votes Candidate A_6 Candidate A_8 Candidate A_5 Voter Votes Table
  • 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Write sharding – Merging results Votes Table Candidate A_2 Candidate B_1 Candidate B_2 Candidate B_3 Candidate B_5 Candidate B_4 Candidate B_7 Candidate B_6 Candidate A_1 Candidate A_3 Candidate A_4 Candidate A_5 Candidate A_6 Candidate A_8 Candidate A_7 Candidate B_8 Periodic Process Candidate A Total: 2.5M 1. Sum 2. Store Voter
  • 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Write sharding – Trade-in orders ShipmentService
  • 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #3 – GSI Write Sharding (15 minute) What you’ll learn: • Use the same server logs data from the previous lab, and query the selected list of 404 error records • The GSI was already created, review the GSI definition • Query the GSI to retrieve the records selectively, also include sort key • Review the Python scripts Workshop
  • 36. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Data modeling: GSI overloading • Working with the 5 GSI default limit • Overload attribute values based on an item’s context Example: Query Employee Database by (1) Employee Name (5) Current Job role (2) Desk (6) Employees in a City (3) Hire Date (7) Warehouse Location (4) Quarterly Sales (8) Employee ID …. and many more
  • 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Data modeling: GSI overloading Partition Key = “Employee ID” Sort Key = (Let’s look at final design) DynamoDB Table design… Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
  • 38. © 2018, 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
  • 39. © 2018, 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
  • 40. © 2018, 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
  • 41. © 2018, 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
  • 42. © 2018, 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
  • 43. © 2018, 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
  • 44. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 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”. Example: Query Employee Database by (1) Employee Name (2) Desk (3) Hire Date (4) Quarterly Sales
  • 45. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 46. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 47. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 48. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 49. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 50. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #4 – GSI Key Overloading (15 minute) What you’ll learn: • Load the Employee data, create an overloaded-GSI, and query the results! Workshop
  • 51. © 2018, 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
  • 52. © 2018, 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
  • 53. © 2018, 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
  • 54. © 2018, 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
  • 55. © 2018, 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
  • 56. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 57. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #5 – 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
  • 58. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Data modeling: Composite sort keys • Define hierarchical relationships • Execute selective queries
  • 59. © 2018, 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
  • 60. © 2018, 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)
  • 61. © 2018, 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 + =
  • 62. © 2018, 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
  • 63. © 2018, 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'
  • 64. © 2018, 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” )
  • 65. © 2018, 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
  • 66. © 2018, 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
  • 67. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 68. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. In the upcoming lab…
  • 69. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #6 – Composite keys (15 minute) What you’ll learn: • Query employee 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
  • 70. © 2018, 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 invoice ID (2) Get invoices by bill ID
  • 71. © 2018, 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 invoice ID, (2) Get invoices by bill ID 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
  • 72. © 2018, 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 invoice ID, (2) Get invoices by bill ID 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
  • 73. © 2018, 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 invoice ID, (2) Get invoices by bill ID 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
  • 74. © 2018, 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 invoice ID, (2) Get invoices by bill ID 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
  • 75. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #7 – Adjacency Lists (10 minute) What you’ll learn: • Many-to-many relationships between Invoices, Bills & Customers using Adjacency lists and an overloaded GSI partition key. • Query all Bills for an Invoice • Query all invoices for a Bill. Workshop
  • 76. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. DynamoDB Streams and AWS Lambda
  • 77. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. DynamoDB Streams as triggers Lambda function Notify change Item/Table Level Metrics Amazon CloudSearch Amazon Kinesis Firehose
  • 78. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. DynamoDB Streams N e a r - r e a l - t i m e m e t r i c s a n d a g g r e g a t i o n s
  • 79. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Exercise #8 – 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 AWS Identity and Access Management [IAM] policies) to read the streams and write to the target Workshop
  • 80. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Padma Malligarjunan - @theRealPadma Sean Shriver - @sean_shriver
  • 81. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.