DynamoDB Flashcards
What is DynamoBD
- 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 is NoSQL different then AWS RDS options
- 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
What is the maximum size of an item (aka row)
400kb
What data types are supported in dynamoDb?
- 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).
What are requirements for a Primary Key?
Must be unique
Must be ‘diverse’ so that the data is distributed
What is a sort key?
A dynamoDB primary key can consist of both a primary key and a sort key
The combination must be unique
Sort key == range key
What are Read Capacity Units (RCU)?
throughput for reads
What are Write Capacity Units (WCU)?
throughput for writes
What is the formula for calculating WCUs?
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
What is the default read consistency for dynamoDB?
DynamoDB uses Eventually Consistent Reads, but GetItem, Query & Scan provide a “ConsistentRead” parameter you can set to True
What is the formula for calculating dynamoDB RCU’s?
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
What term is used to describe rows in a dynomoDB table?
Items
What term is used to describe columns in a dynomoDB table?
Attributes
Can throughput be exceeded temporarily in a dynomoDB table?
Yes, by using burst credits
What happens if there are burst credits are empty in a dynomoDB table?
you’ll get a ‘ProvisionedThroughputException’ error
How do partitions affect RCUs and WCUs?
RCUs and WCUs are spread evenly across partitions
What happens if the defined RCU or WCU in dynomoDB is exceeded?
You get a ‘ProvisionedThroughputExceeded’ error
What is the most popular reason to receive a ‘ProvisionThroughputExceededException’ in dynomoDB?
- Hot Keys: one partition key is being read too many times (popular item for ex)
- Hot partitions
- Very Large Items: remember that RCU and WCU depends on size of items
What are some possible solutions to a ‘ProvisionedExceptionError’ in dynamoDB?
- Exponential back-off when exception is encountered (already in SDK)
- Distribute partition keys as much as possible
- If RCU issue, use DynamoDB Accelerator (DAX)
What is the API command to write data to DynamoDB?
- PutItem
- Consumes WCU
What is the API command to update data in DynamoDB?
UpdateItem
What are conditional writes in DynamoDB?
Places a condition on an item as to when it can be updated.
Example:
Item can only be updated if value = x
What is the API call for deleting an item?
DeleteItem
Deletes an Individual row (Item)
Can you conditionally perform a delete in dynamoDB?
Yes
What is the API call to delete a table in dynamoDB?
DeleteTable
Much quicker tehn calling DeleteItem for each item in the table.
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
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
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
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)
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
What are the 2 main ways to get data from a dynamoDB table?
- Query
- Scan
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
Describe dynamoDB scans
- The entire table is scanned and then data is filtered out (inefficent)
- Consumes a lot of RCU