DynamoDB Flashcards

1
Q

What is DynamoBD

A
  • DynamoDB is a fully Managed NoSQL database
  • It is highly available with replication across 3 AZs
  • Low cost and autoscaling capabilities
  • Must have a provisioned read and write capacity units
  • It is an optimistic locking/concurrency database
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is NoSQL different then AWS RDS options

A
  • A NoSQL database in non-relational
  • You procure table(s) not a database
  • Each table must have a primary key
  • Each table can have an infinite # of items (aka rows), but size is limited to 400kb
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the maximum size of an item (aka row)

A

400kb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What data types are supported in dynamoDb?

A
  • String
  • Number
  • Binary
  • Boolean
  • Null
  • List
  • Map
  • String Set
  • Number Set
  • Binary Set
  • Simply put - dynamoDB will support Scaler Values (one value at a time), document values (multiple values of different type), and Sets (Multiple values of the same type).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are requirements for a Primary Key?

A

Must be unique
Must be ‘diverse’ so that the data is distributed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a sort key?

A

A dynamoDB primary key can consist of both a primary key and a sort key
The combination must be unique
Sort key == range key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Read Capacity Units (RCU)?

A

throughput for reads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are Write Capacity Units (WCU)?

A

throughput for writes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the formula for calculating WCUs?

A

One WCU = 1 write per second for an item up to 1KB in size

Example:
we write 10 objects per seconds of 2 KB each.
We need 10 * 2 = 20 WCU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the default read consistency for dynamoDB?

A

DynamoDB uses Eventually Consistent Reads, but GetItem, Query & Scan provide a “ConsistentRead” parameter you can set to True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the formula for calculating dynamoDB RCU’s?

A

Strongly Consistent Reads

  • 1 read per second for an item up to 4 KB in size

Eventually Consistent Reads

  • 2 reads per second, for an item up to 4 KB in size.

If the items are larger than 4 KB, more RCU are consumed (applies to both eventually / strongly consistent reads)

EXAMPLE:

10 strongly consistent reads per seconds of 4 KB each We need 10 * 4 KB / 4 KB = 10 RCU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What term is used to describe rows in a dynomoDB table?

A

Items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What term is used to describe columns in a dynomoDB table?

A

Attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can throughput be exceeded temporarily in a dynomoDB table?

A

Yes, by using burst credits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens if there are burst credits are empty in a dynomoDB table?

A

you’ll get a ‘ProvisionedThroughputException’ error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do partitions affect RCUs and WCUs?

A

RCUs and WCUs are spread evenly across partitions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens if the defined RCU or WCU in dynomoDB is exceeded?

A

You get a ‘ProvisionedThroughputExceeded’ error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the most popular reason to receive a ‘ProvisionThroughputExceededException’ in dynomoDB?

A
  1. Hot Keys: one partition key is being read too many times (popular item for ex)
  2. Hot partitions
  3. Very Large Items: remember that RCU and WCU depends on size of items
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are some possible solutions to a ‘ProvisionedExceptionError’ in dynamoDB?

A
  1. Exponential back-off when exception is encountered (already in SDK)
  2. Distribute partition keys as much as possible
  3. If RCU issue, use DynamoDB Accelerator (DAX)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the API command to write data to DynamoDB?

A
  • PutItem
  • Consumes WCU
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the API command to update data in DynamoDB?

A

UpdateItem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are conditional writes in DynamoDB?

A

Places a condition on an item as to when it can be updated.

Example:

Item can only be updated if value = x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the API call for deleting an item?

A

DeleteItem

Deletes an Individual row (Item)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Can you conditionally perform a delete in dynamoDB?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the API call to delete a table in dynamoDB?

A

DeleteTable

Much quicker tehn calling DeleteItem for each item in the table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the benefit of Batch Writing in DynamoDB?

A
  • Batching allows you to save in latency by reduing the number of API calls done against DynamoDB
  • Operations are done in parallel for better efficency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What happens if part of a batch fails in dynamoDB?

A

The API contains the ability to retry failed items by using that exponential back-off algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the API call for batching writes in DynamDB? Describe its properties.

A
  • API call = BatchWriteItem
  • Up to 25 PutItem and / or DeleteItem in one call
  • Up to 16 MB of data written
  • Up to 400 KB of data / item
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the API call for Reading data in DynamoDB? What are its properties?

A
  • API call = GetItem
  • Read based on primary key
  • Primary Key = HASH or HASH-RANGE
  • Eventually consistent read by default
  • Option to use strongly consistent reads (more RCU - might take longer)
  • ProjectionExpression can be specified to include only certain attributes (similar to JPA call in Java)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is the API call for batching reads in DynamoDB? What are its properties?

A
  • API call = BatchGetItem
  • Up to 100 items
  • Up to 16 MB of data
  • Items are retrieved in parallel to minimize latency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What are the 2 main ways to get data from a dynamoDB table?

A
  • Query
  • Scan
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Describe DynamoDB Queries.

A
  • Return items based on
    • Partition Key
    • Sort Key
    • FilterExpression (this happens client side)
  • Can query table, a local secondary index or a global secondary index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Describe dynamoDB scans

A
  • The entire table is scanned and then data is filtered out (inefficent)
  • Consumes a lot of RCU
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

How can you increase the performance of dynamoDB scans?

A
  • Use Parallel Scans - BUT this Increases the throughput and RCU consumed
  • Can use a ProjectExpression + FilterExpress (no change to RCU though)
35
Q

What is a local Secondary Index in dynamoDB?

A
  • Alternate range key for the table
  • Can have up to 5 local secondary indexes per table
  • The sort key consists of exactly one scalar attribute
  • The attribute that you choose must be a scalar String, Number, or Binary
  • LSI must be defined at table creation time
36
Q

What is a Global Secondary Index (GSI) in DynamoDB?

A
  • Helps speed up queries on non-key attributes
  • GSI = partition key + optional sort key
  • Must define RCU / WCU for the index
  • You CAN add / modify GSI (unlike LSI)
  • The index is a new ‘table’ and you can project attributes on it
37
Q

(T /F) DynamoDB Indexes can cause throttling

A

True

38
Q

For Global Secondary Indexes (GSI) in dynamoDB, what happens if the writes are throttled?

A
  • The main table will be throttled as well - this is even true if you HAVE provisioned enough WCUs for the MAIN table
  • So choose GSI carefully and be sure that your GSI has enough WCUs assiged to it. Otherwise, a throttle write on the GSI will = a throttle write on the main table.
39
Q

Are there any special throttle considerations for Local Secondary Indexes (LSI)?

A

No. The LSI uses the WCU and RCU of the main table (because its part of the main table unlike GSI that is a seperate table)

40
Q

What is DynamoDB DAX

A
  • Dax = DynamoDB Accelerator
  • Seamless cache for DynamoDB, no application rewrite.
  • Writes go through DAX to DynamoDB
  • Solves the hot key problem
41
Q

What is the default TTL for DAX caches?

A

5 minutes

42
Q

What is the maximum number of nodes in a dynamoDB - dax custer?

A

10

43
Q

What is the difference between DAX and ElastiCache

A
  • DynamoDB is good for individual query and/or scan caches
  • ElastiCache is good for aggragated data
44
Q

What are DynamoDB Streams?

A
  • Changes in DynamoDB (Create, Update, Delete) can end up in a DynamoDB Stream
  • Stream can be read by AWS lambda and EC2 instances
  • Stream has 24 hours of data retention.
  • Records are not retroactivley populated in a stream after enabling it
45
Q

What types of information can be written to a dynamoDB stream?

A
  • KEYS_ONLY: only key attributes of the modified item
  • NEW_IMAGE: The entire item, as it appears after it was modified
  • OLD_IMAGE: the entire item, as it appears before it was modified
  • NEW_AND_OLD_IMAGES: Both the new and old images of the item
46
Q

What are dynamoDB streams made of? Do you need to provision them?

A
  • DynamoDB streams are made of shards.
  • You do NOT need to provision them, this is automated by AWS.
47
Q

How does dynamoDB Streams and Lambda work together?

A
  • You need to define an Event Source Mapping to read from a dynamoDB stream
  • You need to ensure the Lambda function has approporiate permissions
  • Your lambda function is invoked synchronously
48
Q

What is a dynamoDB transaction?

A
  • Ability to create / update / delete multiple items in different tables at the same time.
  • Its an all or nothing type of operation
49
Q

What is DynamoDB - TTL (time to live)?

A
  • It is an atribute on an item that defines and expiry date / time
  • TTL is provided at no extra cost
  • it is a background task operated by the DynamoDB service itself.
50
Q

Do DynamoDB TTL deletions utilize RCAA / WCUs?

A

No

51
Q

Why would you use TTL on a dynamoDB item?

A
  • Helps reduce storage and manage the table size overtime
  • May help adhere to regulatory norms
52
Q

How long does it take for DynamoDB ttl items to be deleted once they’ve hit their expiry date?

A

Item should be deleted within 48 hours

53
Q

Are DynamoBD TTL items also deleted from GSI /LSI?

A

Yes

54
Q

(T/F) DynamoDB Streams ca help recover expired (TTL) items.

A

True

55
Q

What is a dynamDB –projection-expression?

A

A list of attributs to retrieve

56
Q

What is dynamoDB –filter-expression?

A

filter results

57
Q

In what case(s) would you use an dynamoDB transaction?

A

When data needs to be created/updated/deleted in related tables

58
Q

Can DynamoDB be used to store session state data?

A

Yes - probably the best option to do so

59
Q

What are the four different write types in dynamoDB? Describe each.

A
  1. Concurrent Writes - users can write to an item at the same time. Last update wins.
  2. Conditional Writes - updates/deletes can only occur on an item if the item meets a specific condition
  3. Atomic Writes - Items can be increased or decreased by a certain values concurrently
  4. Batch Writes - Write / update many items at once
60
Q

Do dynamoDB table scale horizontally or vertically?

A

horizontally

61
Q

You would like to perform an efficient Query on an attribute that is not part of your table’s primary key. What do you recommend?

A

Create a Globl Secondary Index (GSI)

62
Q

Which feature of DynamoDB allows it to achieve Optimistic Locking?

A

Conditional Writes

63
Q

What is the difference between a Global Secondary Index (GSI) and Local Secondary Index (LSI) in dynamoDB?

A

Global secondary index

an index with a partition key and a sort key that can be different from those on the base table

Local secondary index

an index that has the same partition key as the base table, but a different sort key

64
Q

How can the inefficency of table scans be limited on DynamoDB?

A

You can limit the impact of table scans by using ‘Limit’ or reduce size the size of the result and pause.

65
Q

In Dynamo DB, can the primary key be defined or changed after table creation?

A

No. The primary key must be defined at table creation

66
Q

What types of primary keys does dynamoDB support?

A

DynamoDB supports two different kinds of primary keys

Partition key – A simple primary key, composed of one attribute known as the partition key.

Partition key and sort key – Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key.

67
Q

What is another name for a partition key in dynamoDB?

A

Hash Attribute

68
Q

What is an alternative name for the sort key in dynamoDB?

A

range key

69
Q

What is the data limit returned from a dynamoDB query

A

Return up to 1 MB of data or # of items specified in Limit

70
Q

Can the results of a dynamoDB query be paginated?

A

yes

71
Q

Are indexed (GSI and LSI) queried in a dynamoDB query?

A

Yes, they can be queried along with the table.

72
Q

How many Local Secondary Indexes (LSI) can be added to a dynamoDB table?

A

Up to 5

73
Q

What is a Global Table in dynamoDB?

A

A table that is replicated into multiple regions.

Great for multi-region applications because it reduces latency by giving the user access to the table closest to them.

74
Q

What are some of the main requirements for global tables?

A
  • The same write capacity is requried.
  • All table must have the same name.
  • All tables must have the same primary key.
  • All tables must be empty.
75
Q

What happens if an update is made to the same item in a global table at the same time?

A

The last write wins.

76
Q

What are some recommendations for choosing a sort key in dynamoDB?

A

Data can be queried with

  • starts-with
  • between
  • >
  • <
77
Q

Are Global Secondary Indexes replicated as part of a Global Table in dynamoDb?

A

No. They must be manually added to each region where needed.

78
Q

For dynamoDb on-demand backup and restore, what gets backed up?

A
  • Local and Globacl Secondary Indices
  • DynamoDb Steams
  • Provisioned read and write capacity
79
Q

For dynamoDb on-demand backup and restore, what does not get backed up and restored?

A
  • Autoscaling policies
  • Access policies
  • CloudWatch metrics and alarms
  • Stream settings
  • TTL Settings
80
Q

What is dynamoDb point-in-time recovery? How long is it available?

A
  • Protects from accidental deleteion
  • No schedule on-demand back-ups are needed
  • Available for 35 days (can not do more or less time)
  • Restorable to 5 minutes from the current time
81
Q

For dynamoDb Point-In time recovery, What gets restored?

A
  • Local and Global secondary indices
  • Provisioned Read/Write capacity
  • Encryption settings
82
Q

For dynamoDb Point-In time recovery, What does not get restored?

A
  • Auto Scaling policies
  • Access policies
  • ClourdWatch meterics and alarams
  • Stream Settings
  • TTL settings
  • Point-in-Time recovery settings
83
Q

What are the main differences in use cases between on-demand backup and point-in-time recovery for dynamoDb?

A

On-Demand Backup

  • Best for regulatory compliance
  • Designed for long-term data archival

Point-In-Time Recovery

  • Best for disaster recovery
  • Can be used for compliance if data retention time is 35 days or below