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
What is the API call to delete a table in dynamoDB?
DeleteTable Much quicker tehn calling DeleteItem for each item in the table.
26
What is the benefit of Batch Writing in DynamoDB?
* 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
27
What happens if part of a batch fails in dynamoDB?
The API contains the ability to retry failed items by using that exponential back-off algorithm
28
What is the API call for batching writes in DynamDB? Describe its properties.
* 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
29
What is the API call for Reading data in DynamoDB? What are its properties?
* 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)
30
What is the API call for batching reads in DynamoDB? What are its properties?
* API call = ***BatchGetItem*** * Up to 100 items * Up to 16 MB of data * Items are retrieved in parallel to minimize latency
31
What are the 2 main ways to get data from a dynamoDB table?
* Query * Scan
32
Describe DynamoDB Queries.
* 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
33
Describe dynamoDB scans
* The entire table is scanned and then data is filtered out **(inefficent)** * Consumes a lot of RCU
34
How can you increase the performance of dynamoDB scans?
* Use ***Parallel Scans*** - BUT this Increases the throughput and RCU consumed * Can use a ***ProjectExpression*** + ***FilterExpress*** (no change to RCU though)
35
What is a local Secondary Index in dynamoDB?
* 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
What is a Global Secondary Index (GSI) in DynamoDB?
* 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
(T /F) DynamoDB Indexes can cause throttling
True
38
For Global Secondary Indexes (GSI) in dynamoDB, what happens if the writes are throttled?
* 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
Are there any special throttle considerations for Local Secondary Indexes (LSI)?
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
What is DynamoDB DAX
* Dax = DynamoDB Accelerator * Seamless cache for DynamoDB, no application rewrite. * Writes go through DAX to DynamoDB * Solves the hot key problem
41
What is the default TTL for DAX caches?
5 minutes
42
What is the maximum number of nodes in a dynamoDB - dax custer?
10
43
What is the difference between DAX and ElastiCache
* DynamoDB is good for individual query and/or scan caches * ElastiCache is good for aggragated data
44
What are DynamoDB Streams?
* 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
What types of information can be written to a dynamoDB stream?
* **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
What are dynamoDB streams made of? Do you need to provision them?
* DynamoDB streams are made of shards. * You do NOT need to provision them, this is automated by AWS.
47
How does dynamoDB Streams and Lambda work together?
* 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
What is a dynamoDB transaction?
* Ability to create / update / delete multiple items in different tables ***at the same time.*** * Its an all or nothing type of operation
49
What is DynamoDB - TTL (time to live)?
* 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
Do DynamoDB TTL deletions utilize RCAA / WCUs?
No
51
Why would you use TTL on a dynamoDB item?
* Helps reduce storage and manage the table size overtime * May help adhere to regulatory norms
52
How long does it take for DynamoDB ttl items to be deleted once they've hit their expiry date?
Item should be deleted within 48 hours
53
Are DynamoBD TTL items also deleted from GSI /LSI?
Yes
54
(T/F) DynamoDB Streams ca help recover expired (TTL) items.
True
55
What is a dynamDB --projection-expression?
A list of attributs to retrieve
56
What is dynamoDB --filter-expression?
filter results
57
In what case(s) would you use an dynamoDB transaction?
When data needs to be created/updated/deleted in related tables
58
Can DynamoDB be used to store session state data?
Yes - probably the best option to do so
59
What are the four different write types in dynamoDB? Describe each.
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
Do dynamoDB table scale horizontally or vertically?
horizontally
61
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?
Create a Globl Secondary Index (GSI)
62
Which feature of DynamoDB allows it to achieve Optimistic Locking?
Conditional Writes
63
What is the difference between a Global Secondary Index (GSI) and Local Secondary Index (LSI) in dynamoDB?
**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
How can the inefficency of table scans be limited on DynamoDB?
You can limit the impact of table scans by using 'Limit' or reduce size the size of the result and pause.
65
In Dynamo DB, can the primary key be defined or changed after table creation?
No. The primary key must be defined at table creation
66
What types of primary keys does dynamoDB support?
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
What is another name for a partition key in dynamoDB?
Hash Attribute
68
What is an alternative name for the sort key in dynamoDB?
range key
69
What is the data limit returned from a dynamoDB query
Return up to 1 MB of data or # of items specified in Limit
70
Can the results of a dynamoDB query be paginated?
yes
71
Are indexed (GSI and LSI) queried in a dynamoDB query?
Yes, they can be queried along with the table.
72
How many Local Secondary Indexes (LSI) can be added to a dynamoDB table?
Up to 5
73
What is a Global Table in dynamoDB?
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
What are some of the main requirements for global tables?
* 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
What happens if an update is made to the same item in a global table at the same time?
The last write wins.
76
What are some recommendations for choosing a sort key in dynamoDB?
Data can be queried with * starts-with * between * \> * \<
77
Are Global Secondary Indexes replicated as part of a Global Table in dynamoDb?
No. They must be manually added to each region where needed.
78
For dynamoDb on-demand backup and restore, what gets backed up?
* Local and Globacl Secondary Indices * DynamoDb Steams * Provisioned read and write capacity
79
For dynamoDb on-demand backup and restore, what ***does not*** get backed up and restored?
* Autoscaling policies * Access policies * CloudWatch metrics and alarms * Stream settings * TTL Settings
80
What is dynamoDb point-in-time recovery? How long is it available?
* 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
For dynamoDb Point-In time recovery, What gets restored?
* Local and Global secondary indices * Provisioned Read/Write capacity * Encryption settings
82
For dynamoDb Point-In time recovery, What ***does not*** get restored?
* Auto Scaling policies * Access policies * ClourdWatch meterics and alarams * Stream Settings * TTL settings * Point-in-Time recovery settings
83
What are the main differences in use cases between on-demand backup and point-in-time recovery for dynamoDb?
_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