DynamoDB Flashcards
What are the different data types supported by DDB?
Scalar - String, Number, Binary, Boolean, Null
Document - List, Map
Set - String, Number, Binary
What is the max item size?
400 KB
What is the difference between Provisioned and On-Demand Mode?
Provisioned - specify number of reads/writes per second; plan capacity beforehand; pay for provisioned RCUs/WCUs
On-Demand - auto scaling RCUs/WCUs; pay for what you use (more expensive)
What happens when throughput maximum is reached in provisioned mode?
Can be exceeded temporarily using ‘Burst Capacity’
- If this capacity has been consumed, will receive a ‘ProvisionedThroughputExceededException’
- Use exponential backoff retry on this exception
What is one WCU?
One write per second for an item up to 1KB in size (if the item is larger than 1KB, WCUs round to up to the next whole number - e.g. 6 writes per second for 4.5KB -> 6 * 5 WCUs due to rounding).
What are the two different types of read, and what are their RCU costs?
Strongly vs. eventually consistent read (strongly is twice the RCU cost of eventually)
How do you force a strongly consistent read on query?
Set ‘ConsistentRead’ parameter to Truew in API calls (GetItem, BatchGetItem, Query, Scan)
What is one RCU?
One Strongly Consistent Read or two Eventually Consistent Reads per second, for an item up to 4KB in size.
How are RCUs and WCUs spread across partitions?
Evenly
What are some common causes of ‘ProvisionedThroughputExceededException’?
Hot keys - one partition key being read too many times (e.g., popular item)
Hot partition - partition keys do not have enough cardinality
Very large items - RCU and WCU depends on size of items, so large items consumer more units.
How does On-Demand mode differ in terms of reads/writes? Give a use case of On-Demand mode.
Charged for reads/writes that you use in terms of RRUs and WRUs (read request units and write request units)
- 2.5x more expensive than provisioned capacity
- Use cases: unknown workloads, unpredictable application traffic
What is the difference between PutItem and UpdateItem?
PutItem - creates a new item or fully replace an old item
UpdateItem - edits the specified attributes of an existing item, or adds a new item if one doesn’t exists
What is a ProjectionExpression in a GetItem request?
Can be specified to retrieve only certain attributes
What parameters can you specify in a query?
KeyConditionExpression - Partition key equals (required); Sort key conditions (<, > etc.) (optional)
FilterExpression - Additional filtering after the query operation, use only with non-key attributes
What is the size limit on the return value of a query, and how should you get more data than this limit?
1MB - use pagination to get more data
State the properties of a BatchWriteItem call.
- Up to 25 PutItem and/or DeleteItem in one call (no UpdateItem)
- Up to 16MB of data written, up to 400KB of data per item
- UnprocessedItems property for failed write operations (exponential backoff or add WCU)
State the properties of a BatchGetItem call.
- Return items from one or more tables
- Returns up to 100 items, up to 16MB of data
- UnprocessedKeys property for failed read operations.
What is the difference between a filter expression and condition expression?
Filter is for reads, Condition is for writes
Describe LSIs
Alternative sort key for your table (using the same partition key)
- Sort Key consists of one scalar attribute
- Up to 5 LSIs per table
- Must be defined at table creation time
Describe GSIs
Alternative Primary Key
- Speed up queries on non-key attributes
- Index Key consists of scalar attributes
- Must provision RCUs and WCUs for the index
- Can be added/modified after table creation
How does throttled differ between GSIs and LSIs?
Even though GSIs are given their own WCUs and RCUs, if writes are throttled on the GSI, then the main table will also be throttled.
LSIs use the capacity from the main table, so no special considerations.
How does optimistic locking work?
Conditional write - each item has an attribute that acts as a version number. The write request passes in the version it wants to change, and if there is a mismatch, the write does not go through.
Give a high level description of DAX, and the problem that it solves.
DDB accelerator - a highly available and seamless cache.
- Solves hot key problem (too many reads, these now come from the cache)
When would you use ElastiCache or DAX?
DAX - good for individual objects resulting from query or scan
ElastiCache - good for aggregation results (i.e., logic/computation applied to results)