Section 14: AWS Serverless: DynamoDB Flashcards
How do NoSQL databases scale? (direction)
Horizontally
What replication do you get out of the box with DynamoDB
Replication accross 3 AZ
How much can DynamoDB scale?
It can scale to massive workloads
Millions of requests per seconds
Trillions of rows
TBs of storage
All of it completely automatically
How does DynamoDB enable event driven programming?
By providing DynamoDB streams
Does DynamoDB provide the ability to create โdatabasesโ?
No, only tables (itโs a fully managed service, DynamoDB โisโ the DB)
How many rows can a DynamoDB table have?
Infinite
What must all tables have?
A primary key
What are the two types of primary key?
Simple primary key (partition key only)
Composite primary key (partition key + sort key)
What do each item in a DynamoDB table have?
Primary key
Attributes
What is the maximum size of an item in DynamoDB table?
400 KB
Do all items have to share the same attributes in DynamoDB table?
No, they can all have their own, all attributes are nullable
What data types are supported in DynamoDB tables?
Scalar Types
Document Types
Set Types
What Scalar Types are available?
String Number Binary Boolean Null
What Document Types are available?
List
Map
What is the List type?
Ordered collection of values (Similar to JSON array, values donโt have to be of the same type)
What is the Map type?
Unordered collection of name-value pairs (Similar to JSON object (actually ideal for the purpose of storing JSON objects in DynamoDB))
What Set Types are available?
String Set
Number Set
Binary Set
What is a String Set?
โListโ of strings
What is a Number Set?
โListโ of numbers
What is a Binary Set?
โListโ of binaries
What is the role of the partition key in a DynamoDB table?
It defines the partition where the item is going to get stored
How to make sure that data is highly distributed in a DynamoDB table with a simple primary key?
By having diverse partition keys (primary keys)
How is data grouped when using the composite primary key in a DynamoDB table?
Grouped by partition key
What is another name given to the sort key?
Range key
What must be unique when using the simple primary key in a DynamoDB table?
Partition key
What must be unique when using the composite primary key?
The combination (partition key + range key)
What are the two pricing model of DynamoDB tables?
On-demand capacity
Provisioned capacity
How to get better rates when using provisioned capacity?
By purchasing reserved capacity (Similar to how reserved instances work in EC2)
What are the units used to configure the read and write throughput of provisioned capacity DynamoDB tables?
Read Capacity Units (RCU)
Write Capacity Units (WCU)
What does 1 WCU represent?
One write per second for an item up to 1 KB
What happens if you need to write an item which weights more than 1 KB?
More WCU are consummed
Exercice: We write 10 objects per seconds of 2 KB each, how many WCU do we need?
20 WCU
Exercice: We write 6 objects per second of 4.5 KB each, how many WCU do we need?
30 WCU
Exercice: We write 120 objects per minute of 2 KB each, how many WCU do we need?
4 WCU
What is the difference between strongly consistent reads and eventually consistent reads?
With strongly consistent reads you are sure that even if you read right after a write, you will get the data
With eventually consistent reads, you may not get the data if you read right after a write, but you will eventually get the data (if you request it later enough)
Why do we might not get the data if we do an eventually consistent read just after a write?
If we happen to read from an AZ where our written data has not yet been replicated, we might not find the data
By default, DynamoDB uses eventually consistent reads, how can we โenableโ consistent read?
By setting the ConsistentRead parameter to true in our read request
What does 1 RCU represent?
One strongly consistent read per second, or two eventually consistent reads per second, for an item up to 4 KB in size
If the items read are larger than 4 KB, what will happen?
More RCU will be consummed
Exercice: We do 10 strongly consistent reads per seconds of 4 KB each, how many RCU are consummed?
We need 10 * 4 KB / 4 KB = 10 RCU
Exercice: We do 16 eventually consistent reads per seconds of 12 KB each how many RCU are consummed?
We need (16 / 2) * ( 12 / 4 ) = 24 RCU
Exercice: We do 10 strongly consistent reads per seconds of 6 KB each how many RCU are consummed?
We need 10 * 8 KB / 4 = 20 RCU (we have to round up 6 KB to 8 KB)
What does DynamoDB divide data into?
Partitions
How to compute the number of partions used by a DynamoDB table?
Capacity = (TOTAL RCU / 3000) + (TOTAL WCU / 1000)
Size = Total Size / 10 GB
Total partitions = CEILING(MAX(Capacity, Size))
How are WCU and RCU spread accross partitions?
Evenly
What error will you get if you exceed your RCU or WCU?
ProvisionedThroughputExceededExceptions
What might be the reason for ProvisionedThroughputExceededExceptions ?
Hot keys/partitions (One partition is being read too many times)
Very large items (RCU/WCU consumption depends on size of items)
What solutions can you try to resolve ProvisionedThroughputExceededExceptions ?
Exponential back off
Distribute partition keys as much as possible
What can you try if you have a lot of reads in a single partition?
Use DynamoDB Accelerator (DAX)
What is DAX?
Seamless cache for DynamoDB
What is the default TTL in DAX?
5 minutes
How many nodes can you have in a DAX cluster?
Up to 10
In how many AZ should your DAX cluster nodes be?
Multi AZ replication (minimum 3 recommended for prod)
What API allows you to write data to a DynamoDB table?
PutItem
UpdateItem
What is the difference beteen PutItem and UpdateItem
PutItem creates an item or replaces an existing one
UpdateItem does a partial update of attributes
What are conditional writes?
A way to write / update only if a certain condition is respected
What API allows you to delete data in DynamoDB table?
DeleteItem
DeleteTable
Can you do a conditional delete?
Yes
What is cheaper/faster between DeleteItem and DeleteTable + CreateTable for deleting all items in a table?
DeleteTable
What does BatchWriteItem allow you to do?
Do 25 PutItem and / or DeleteItem in one call
What is the maximum size of the data written with BatchWriteItem
16 MB
What is the maximum size of the data written PER ITEM with BatchWriteItem
400 KB
What does BatchWriteItem batching provide you?
Reduction in latency (less API calls)
What can you do if part of a batch fails with BatchWriteItem ?
Try the failed items (exponential back-off algorithm)
What is the GetItem read based on?
Primary key
How can you specify which attributes to get from an item read with GetItem?
Use the ProjectionExpression parameter
How many items does BatchGetItem allow you to get?
Up to 100
How many MB of data does BatchGetItem allow you to get?
Up to 16MB
What is inefficient way of querying data in a dynamoDB table, and why so?
Scan, because it will โaccessโ all the data in your table, therefore you will be charged for the entire weight of your table (up to 1 MB)
TODO: Make this answer clearer
What is the efficient way of querying data in a DynamoDB table?
Using the Query API
Query returns items based on?
Partition key (must be = operator) Sort key (=,>,Between,Begin operator) (optional)
How many MB of data can the Query API return?
Up to 1 MB
Can you limit the number of items returned by the Query API?
Yes, with the Limit parameter
What filtering method does not help you with lowering costs in DynamoDB?
FilterExpression
Is pagination an option with Query API?
Yes
Does Scan API consumes a lot of RCU?
Absolutely, and thatโs why it is NOT efficient
What are the two Scan API options which donโt change the RCU consumption?
ProjectionExpression
FilterExpression
How can you get faster performance when using the Scan API, and how does this impact RCU?
Parallel scans
+++ RCU consumption
What does the DynamoDB Query API allow you to query other than tables?
Indexes
What are DynamoDB LSI?
Local Secondary Index
Alternate range key for your table (local to the hash key)
What are the available types for a sort key?
String, Number or Binary
How many LSI can a DynamoDB table have?
Up to 5
When must LSI be defined?
At table creation time
What are DynamoDB GSI?
Global Secondary Index
Used to speedup queries on non-key attributes
What is a DynamoDB GSI like?
A new โtableโ linked to the base table
How is called the group of attributes that are copied from a table to a secondary index?
A projection
Once a DynamoDB table has been created, which can you add later? LSI or GSI?
GSI
What must you define when creating a GSI (for the GSI specifically)?
Its own RCU and WCU
What will happen if you perform heavy write activity on the table but the GSI does not have enough WCU?
The write activity on the BASE TABLE will be throttled
What is the recommended WCU for a GSI to avoid potential throttling?
Equal or greater than the base table
What are the special throttling considerations when dealing with LSI?
None
What RCU/WCU does the LSI uses?
The ones of the main table
DynamoDB features of conditional update / delete makes it an _________________ database
optimistic locking / concurrency
Can you PutItem/BatchWriteItem on an GSI?
No! Itโs an index, you can only write to a table.
Why do GSI require WCU?
Base table needs to replicate (therefore write) to the GSI
What is a DynamoDB Stream?
A stream which can be configured to record changes (Create, Update, Delete) in a DynamoDB table
How long is the retention periods of messages in a DynamoDB stream?
24 hours
What can DynamoDB streams be used for?
React to changes in real time (integration with Lambda)
Implement cross region replication
What can you use to delete items of a DynamoDB table after a certain time?
Configure TTL in your DynamoDB table
What does TTL stand for?
Time To Live
What is the extra cost associated with TTL?
0$
How many WCU does TTL consumes?
0
Who operates TTL?
DynamoDB, you donโt have to do anything than other than setting up your TTL attribute
How can TTL help you reduce cost?
By deleting expired items, you free up space, therefore get charged less for storage
What CLI options do you need to use to implement pagination in your DynamoDB/S3 queries?
- -max-items
- -starting-token (If it is not the first call, you use the NextToken received in the previous call)
What CLI option allow you to optimize your requests to avoid timeouts?
โpage-size
What are DynamoDB transactions?
A new feature which give us the ability to create / update / delete multiple rows in different tables at the same time (all or nothing)
How much WCU / RCU does transactions consume?
2 WCU per items of 1 KB
2 RCU per items of 4 KB
Are there VPC endpoints to DynamoDB table?
Yes
How is DynamoDB secure?
Access fully controlled by IAM
Encryption at rest using KMS
Encryption in flight using SSL / TLS
What are the available backup / restore features offered by DynamoDB?
Point in time restore like RDS
What are DynamoDB global tables?
Multi region, fully replicated, high performance tables
What can you use to migrate from Mongo, Oracle, Mysql, etc. to DynamoDB?
Amazon DMS
What does DMS stand for?
Database Migration Service