DynamoDB schema design

Data Modeling with DynamoDB Workshop - AWS Virtual Workshop
"Amazon DynamoDB is the most scalable database service offered by AWS. Amazon DynamoDB was built to scale with a serverless architecture that supports the largest internet-scale applications, including Disney+ and Fidelity Investments. Being a NoSQL database, DynamoDB is the perfect choice for microservice based architectures. For customers starting their journey of application modernization, DynamoDB is a great place to start. This session will start off covering the data modeling basics for DynamoDB, such as terminology, then progress into more advanced topics including related data, secondary indexes and single table design." Learning Objectives: * Objective 1: Understand the data modeling basics for DynamoDB. * Objective 2: Contrast the NoSQL, schemaless of DynamoDB data models to relational. * Objective 3: Walk through the data modeling process including entity-relationship diagram (ERD), access patterns, designing primary keys and more. ***To learn more about the services featured in this talk, please visit: https://aws.amazon.com/dynamodb To download the slides visit: https://pages.awscloud.com/rs/112-TZM-766/images/2023_0302-VW-DAT_Slide-Deck.pdf Subscribe to AWS Developers: https://www.youtube.com/@AWSDevelopers?sub_confirmation=1 Follow Amazon Web Services: Official Website: https://aws.amazon.com/what-is-aws Twitch: https://twitch.tv/aws Twitter: https://twitter.com/awsdevelopers Facebook: https://facebook.com/amazonwebservices Instagram: https://instagram.com/amazonwebservices ☁️ AWS Online Tech Talks cover a wide range of topics and expertise levels through technical deep dives, demos, customer examples, and live Q&A with AWS experts. Builders can choose from bite-sized 15-minute sessions, insightful fireside chats, immersive virtual workshops, interactive office hours, or watch on-demand tech talks at your own pace. Join us to fuel your learning journey with AWS. #AWS
https://www.youtube.com/watch?v=p8phVh6HRkQ

You can play around on DynamoDB for free by using NoSQL workbench for DynamoDB.

Philosophy

  1. Thou shall use one or fewer tables
  1. Thou shall know there are no JOINs
  1. Thou shall use a PK and an optional SK (sort key)
  1. Thou shall use GSIs (global secondary indexes) to group different columns and will not spam GSIs to incur more costs

Patterns

Do nothing

This is bad because, you make more requests than what is nessisary.

Denormalise with JOIN

Stacked with UNION

Stack all normalised relational tables into one dynamoDB table

Note: that the PK will start with what data it contains, ‘cust-123’ will define customer data

GSIs will be used to group rows

Note: using this costs more, so use less often

Note: there is no optimiser to use the GSI for you

Date formats (only talking about it cos its not a type)

(first is a string, second is a number)

These two formats are recommend because they are sortable.

String:

Int:

GSI

A Global Secondary Index (GSI) in DynamoDB is an index that has a partition key and an optional sort key that can be different from those on the base table. This allows for more flexible querying, including the ability to query on any attribute (not just the primary key attributes), and allows for faster access to data.

Best practice:

  1. Use them sparingly, because they cost money to maintain and also take up more storage
  1. Typically used to group data
  1. If only a few rows have a certain column, then GCIs can be good to grab only them columns, by going down the index table and getting all of them, instead of doing a global search
  1. I think some rows can be ignored and not added to the GSI
  1. Dont bother using Local Secondary Index because it is not as flexible as GSI

Do not assume: