0% found this document useful (0 votes)
22 views

RSDB En-Us SG M06 Dynamodb

Uploaded by

michellekangethe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

RSDB En-Us SG M06 Dynamodb

Uploaded by

michellekangethe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Amazon DynamoDB

Database Fundamentals

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Welcome to Amazon DynamoDB.


What you will learn

At the core of the lesson


You will learn how to do the following: Key terms:
• Describe the purpose and function of Amazon • Nonrelational database
DynamoDB. • NoSQL database
• Table item and attribute
• Primary, partition, and sort keys
• Table partition
• Global tables

2 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

In this module, you will discover key concepts that are related to database solutions.
The module will highlight the differences between relational and nonrelational
databases in general and explore concepts and terminology related to the Amazon
DynamoDB NoSQL database.

You will learn how to describe the purpose and function of DynamoDB.
Introduction to DynamoDB

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Welcome to an introduction to DynamoDB, a NoSQL Amazon Web Services (AWS)


database service.
Relational and nonrelational NoSQL databases: Comparison

Relational databases Nonrelational NoSQL databases


• Data is stored in tables by using predefined • Data is stored in tables with a flexible column
columns of specific data types. structure.
• Relationships can be defined between tables • Each item stored in a table can have a different
by using table foreign keys. number and type of data elements.
• Better performance is achieved by adding • Better performance is achieved by adding a new
compute or memory capacity to a single server to an existing pool of database servers.
database server.

4 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Relational databases are used to store data for a wide variety of applications.
Relational databases use normalized database table designs, which means that data
is stored across multiple tables with defined relationships between the tables.

The data stored in a relational database table must match the design for that table.
Every record layout is essentially the same; only the data is different.

Most relational databases run on a single, large database server with a fixed amount
of memory and compute capacity. If better performance is needed, a bigger server
with more memory or compute capacity is used to replace the existing server.

Nonrelational, or NoSQL, databases are more flexible in the way that they store data.

Data for one record in the database can be of a different layout, type, and size from
data for another record in the database.

NoSQL databases run on a group of servers called a cluster, each with its own fixed
amount of memory and compute capacity. If better performance is needed,
additional servers can be added to the existing cluster group.
DynamoDB is a NoSQL database
What is DynamoDB?
A fully managed, serverless, key-value NoSQL
database that does the following:
• Improves performance by keeping data in
memory
• Keeps data secure by encrypting data at
rest
• Protects data with backups and automated
copying of data between AWS Regions

5 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

DynamoDB offers the following advantages:


• Fully managed service: AWS manages all of the underlying compute and storage
needed to store your data.
• Scalability: DynamoDB automatically adds more compute and storage capacity as
your data grows.
• Redundancy: DynamoDB copies your data across multiple AWS Regions to avoid
data loss.
• Recoverability: DynamoDB can restore your data from automatic backup
operations.
• Low latency: Data can be read from a DynamoDB table in a few milliseconds.
• Security: You can use DynamoDB with AWS Identity and Access Management
(IAM) to control access to DynamoDB tables.
• Flexibility: DynamoDB can store several types of data, and each record can have
varying numbers and types of data. JSON is one popular way to store data in
DynamoDB.
How it works

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Next, you’ll look at how DynamoDB works.


Key concepts: Tables

Core concepts behind DynamoDB Example


• Tables In DynamoDB: Similar to relational • Suppose that you want to create a DynamoDB
database systems, DynamoDB stores data in table to store data about your Friends. The Friends
tables. table can do the following:
– The table name and primary key must be – Use an ID number to identify each friend.
specified at table creation. – Use this ID number as the table’s primary
– Each DynamoDB table has at least one key.
column that acts as the primary key.

• The primary key is the only data that is required


when storing a row in a DynamoDB table. Any
other data is optional.

7 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Each DynamoDB table must have a primary key.

Each row in a DynamoDB table must have a distinct value for the primary key.
Key concepts: Attributes

Core concepts behind DynamoDB Example


• A column in a DynamoDB table is called • The Friends table will use the FriendID
an attribute. attribute for the primary key, but other
– An attribute represents a fundamental data attributes might include the following:
element, something that does not need to – Name
be broken down any further. – Hobbies
– An attribute is similar in concept to table – Favorite colors
columns or fields in a relational database.

• A primary key can consist of one or two attributes.

FriendID
Name
Hobbies
FavoriteColors

8 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Relational databases use tables, made up of columns, to store data.

DynamoDB uses tables, made up of attributes, to store data.

The primary key for a DynamoDB table can consist of one or two attributes.
Key concepts: Items

Core concepts behind DynamoDB Example


• An item is a group of attributes that is • Data for each friend is stored as an item.
uniquely identifiable among all of the other – Each friend has an ID plus any other attributes
items. that you want to store about that person.
– Each item consists of one or more – The amount and type of data stored for each
attributes. attribute can vary for each friend.
– Each item is uniquely identified by its
primary key attribute.
– This concept is similar to a table row
in a relational database.

Difference from a relational


database 1
• The number and type of non-primary key Martha Rivera
attributes can be different for each item in dancing,hiking,sailing
a table. red,blue

9 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Relational databases use tables, made up of columns, to store data as rows.

DynamoDB uses tables, made up of attributes, to store data as items.

Each item stored in a DynamoDB table does not need to have the same number or
type of attributes.

This property is a difference between NoSQL tables and relational database tables.
With relational tables, the number and type of data in each row must match the
table’s structure.
Key concepts: Primary keys

Simple primary key Composite primary key


• The primary key consists of one attribute. • The primary key consists of two attributes.
• The attribute is called the partition key or hash • The first attribute is the partition key or hash key.
key. • The second attribute is the sort key or range
attribute.

One attribute Two attributes

REMEMBER: Primary keys uniquely identify each item in the table, so no two items can have the same primary
key.

10 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

A primary key that is based on a single table attribute is called a simple primary key.
The attribute that the primary key is based on is called the partition key or hash key.

A primary key that is based on two table attributes is called a composite primary key.
The first attribute in a composite primary key is called the partition key or hash key.
The second attribute in the composite primary key is called the sort key or range
attribute.

Whether simple or composite, each item must have a unique value for its primary key
attributes.
The concept of partitioning

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Next, you’ll look at how partitioning works.


Key concepts: Partitions

Core concepts behind DynamoDB Example


• DynamoDB tables store item data in partitions. • The value for the FriendID attribute will
– Table data is partitioned and indexed by determine which partition in the Friends table
the primary key. will store the data for that person.
– Each table has one or more partitions.
– New partitions are added as data is added Friends table
to the table.
– Tables whose data is distributed evenly
across multiple partitions generally deliver
Partition 1
the best performance.

• The partition in which an item’s data is stored is


determined by its primary key attribute.
Partition 2

12 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

DynamoDB tables store data in partitions. Each table comprises one or more
partitions.

DynamoDB automatically adds new partitions to a table when the existing partitions
fill with data.
Key concepts: Storing items in partitions
Friends table

Partition 1

Partition 2

FriendID Name Hobbies FavoriteColors


1 Martha Rivera dancing, hiking, sailing red, blue

Partition key Attributes

13 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

This example shows the item data for Martha Rivera being stored in the Friends table.

When choosing the partition to store the data, DynamoDB applies a function to the
partition key attribute of the primary key. In the case of the Friends table, the primary
key is a simple primary key. Therefore, the partition key attribute is the same as the
primary key, which is FriendID.

The value that the function returns will be in either Partition 1 or Partition 2
depending on the value for the FriendID attribute.

In this case, the function chose Partition 1 to store Martha’s data.


Key concepts: Storing attributes in partitions
Friends table

Partition 1

Partition 2

FriendID Name Hobbies FavoriteColors FavoriteGames FavoriteFoods


2 Zhang Wei Painting, hiking, yoga green, blue chess pizza, chicken

FriendID Name Hobbies FavoriteColors


1 Martha Rivera dancing, hiking, sailing red, blue Additional
attributes

14 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

This example shows the item data for another friend, Zhang Wei, which is being
stored in the Friends table.

When choosing the partition to store the data, DynamoDB applies a function to the
partition key attribute, FriendID. In this case, the function chooses Partition 2 to
store Zhang’s data.

Notice that two additional attributes are being stored for Zhang, more than were
stored for Martha. These extra attributes do not present a problem. If an item has a
primary key value, DynamoDB permits each item to have different numbers and types
of attributes.
DynamoDB global tables

© 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Next, you’ll look at the way that DynamoDB global tables can be used to improve
performance and data availability.
Using global tables

Core concepts of global tables Example


• Using the global table option creates a DynamoDB • What if you have millions of friends all over the
table that is automatically replicated across your world who will use your Friends table?
choice of AWS – Global tables will put the table data closer
Regions worldwide. to your friends.
– Deliver fast, local read and write – Being closer to the data means that your
performance for global applications. friends will experience faster query
– Your applications can stay highly available in performance.
the unlikely event of isolation or
degradation of an entire AWS Region.

• Global tables eliminate the difficult work of


replicating data between Regions and resolving
update conflicts between copies.

16 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

The DynamoDB global tables feature provides high availability and scalability across
Regions.

A global table is a collection of one or more DynamoDB tables, which must all be
owned by a single AWS account.

The tables in the collection are also known as replica tables. Each replica stores the
same set of data items.

When you create a global table, you specify the AWS Regions where you want the
table to be available.

DynamoDB performs all of the necessary tasks to create identical tables in these
Regions. It automatically performs ongoing copying of data to all of the tables to keep
their contents in sync.

DynamoDB global tables work well for large-scale applications with globally dispersed
users by accessing the replica that is closest to them.
Global tables example

17 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

This example shows how globally dispersed friends benefit from DynamoDB global
tables by using a mobile application.

Users can access the table replica that is geographically closest to them. This access
enhances your friends’ experience by providing better response times when reading
and writing to the DynamoDB Friends table.
Checkpoint questions

Why are nonrelational (NoSQL) databases a good choice when you must get started
quickly on a project?

Which table attribute is responsible for determining where item data is partitioned?

When you create items in a DynamoDB table, does each entry need to have the same
attributes?

18 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. Why are nonrelational (NoSQL) databases a good choice when you must get
started quickly on a project?

NoSQL databases have flexible schemas, so it is not necessary to do any data


engineering. Developers can quickly and easily work with the data without
needing to understand relationships between data.

2. What table attribute is responsible for determining where item data is


partitioned?

The partition key is responsible for where the data is partitioned.

3. When you create items in a DynamoDB table, does each entry need to have the
same attributes?

No. Because DynamoDB is a NoSQL database, individual items can have different
attributes from other entries.
Key takeaways
• DynamoDB is a fully managed NoSQL database service.
• DynamoDB offers fast access to table data.
• DynamoDB has essentially no table size or throughput limits.
• Global tables reduce the difficulty of replicating data between
Regions and resolving update conflicts.

19 © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

This module includes the following key takeaways:


• DynamoDB is a fully managed NoSQL database service.
• DynamoDB offers consistent, single-digit millisecond latency at any scale.
• DynamoDB has essentially no table size or throughput limits.
• Global tables reduce the difficulty of replicating data between Regions and
resolving update conflicts.
Thank you

© 2022 Amazon Web Services, Inc. or its affiliates. All rights reserved. This work may not be reproduced or redistributed, in whole or in part, without prior written permission from Amazon Web Services, Inc.
Commercial copying, lending, or selling is prohibited. Corrections, feedback, or other questions? Contact us at https://support.aws.amazon.com/#/contacts/aws-training. All trademarks are the property of their
owners.

Thank you for completing this module.

You might also like