DynamoDB Flashcards
Eight things about DynamoDB?
- Fully managed
- Multi-region
- Multi-master
- Durable
- Built-in security
- Backup and restore
- In-memory caching
- Data is stored across multiple AZs
What are the 2 types of reads that DynamoDB provides?
- Strongly Consistent Reads
- Eventually Consistent Reads (Default)
The Key Value and Document database solution for AWS
DynamoDB (NoSQL)
What are the 3 components of a DynamoDB table?
- Keys
- Values
- Attributes
How many partitions does a DynamoDB database start off with?
1
How large can a single DynamoDB partition be? (GB)
10GB
The maximum read and write capacity units for a single DynamoDB partition
3000 Read Capacity Units, 1000 Write Capacity Units
These 2 components make up a composite primary key in DynamoDB
(kəmˈpɑzət)
Partition Key & Sort Key
In Dynamo DB, When using a simple primary key how many items can have the same partition key?
1
In Dynamo DB, What additional key component makes a primary key composite?
Sort key
- (The combination of the partition and the sort has to be unique) There is a secret internal hash function that decides which partition to write data
- New data is added into a partition with similar data, Eg. a category
- Partition Key: Category
- Sort Key: Name
In Dynamo DB, with composite keys multiple items share the same partition key (as long as their sort keys are different)
True or False
True.
- Partition Key: Country
- Sort Key: Citiy
Partition A: VE - CCS VE - MCBO Partition B: CL - STGO CL - CONCE
In Dynamo DB, The 2 methods of retrieving items from a DynamoDB table
Query & Scan
In Dynamo DB, By default what item attributes does a query return?
All attributes
This DynamoDB item retrieval method finds items based on primary key values.
Query
This DynamoDB item retrieval method checks all items, then returns one of more item using filters
Scan
- Scans are one of the most expensive ways to access data in DynamoDB
- Scans can be Slow
In Dynamo DB, which method do you have to avoid because it retrieves everything.
It’s much less efficient than running the other one
Scan
- Scans are one of the most expensive ways to access data in DynamoDB
- Scans can be Slow
With DynamoDB the maximum amount of capacity your application is allowed to read or write per second from a table or index is called this. (The name of the capacity)
Read/Write capacity mode: ___
Provisioned Throughput Capacity
(prəˈvɪʒənd ˈθruˌpʊt kəˈpæsəti)
Provisioned
- RCUs
- WCUs
We can turn on Auto Scaling
Requests that are throttled will be dropped (data lost)
With this DynamoDB capacity type you only pay per request - so you are only paying for what you use
Read/Write capacity mode: ___
On-Demand Capacity
- Provisioned capacity not applicable
- Auto Scaling not applicable
New tables with unknown workloads, unpredictable application traffic
Default upper limits for a table
40,000 RCUs
40,000 WCUs
- Since there is no hard limit On-Demand could become very expensive based on emerging scenarios
In DynamoDB,
What are the 3 requirements for creating a Global Table?
- KMS CMK
- Enable Streams
- StreamViewType (What info is going to be written to the stream)KEYS_ONLY - Only the key attributes of the modified item are written to the stream.NEW_IMAGE - The entire item, as it appears after it was modified, is written to the stream.OLD_IMAGE - The entire item, as it appeared before it was modified, is written to the stream.NEW_AND_OLD_IMAGES - Both the new and the old item images of the item are written to the stream.
How many underlying reads or writes does DynamoDB perform on every item in a transaction?
2
- One to prepare the transaction
- One to commit the transaction
The 2 operations for performing transactions with DynamoDB
- TransacWriteItems
- TranscGetItems
Which format must you provide your TTL value in?
To use TTL you must use a string which needs to be In Epoch format (Datetime represented as numbers)
(ˈipək) format
What is TTL in DynamoDB?
Time To Live
- It’s great for keeping databases small and manageable because some data is deleted when it expires
Eg: Session data, Usage Patterns, Some logs
In DynamoDB this value specifies when an item should expire/delete itself
Time To Live (TTL) Value
Enabling this DynamoDB feature on a table will capture every modification to data items so you can react those changes.
DynamoDB Streams
- It doesn’t not consume RCU
Which of the following is true about DynamoDB streams?
There are three answers:
- Changes are sent in batches at a time
- Changes are sent to Lambda in near real-time
- It doesn’t consume RCU’s
Which of the following are common errors for DynamoDB?
..Exception
.. .. …Exception
- ThrottlingException (ˈθrɑtəlɪŋ ɪkˈsɛpʃən)
This exception might be returned if you perform control plane API operations too rapidly. (CreateTable, UpdateTable, ListTables)
For tables using on-demand mode, this exception might be returned for any data plane API operation if your request rate is too high. (CRUD actions on data in a table)
- ProvisionedThroughputExceededException
Your request rate is too high. The AWS SDKs for DynamoDB automatically retry requests that receive this exception. Your request is eventually successful, unless your retry queue is too large to finish. Reduce the frequency of requests using Error Retries and Exponential Backoff.
The 2 types of secondary indexes available for DynamoDB.
ˈsɛkənˌdɛri
Which Should you use generally?
- LSI - Local Secondary Index
> With initial table (After creation, nothing to do)
> It provides strong consistency
> It can’t exceed 10GB (It’s per partition)
> Composite keys
- GSI Global Secondary Index > Generally use this > Queries on the index can span all of the data across all partition > Maximum 20 per table > Eventual consistency reads
What are some scenarios would be ideal to consider DAX?
(sɪˈnɛrioʊz)
There are two scenarios in the list
It is a fully managed, highly available, in-memory cache for Amazon DynamoDB
- Apps requiring the fastest possible response time for reads
> Real-time bidding, social gaming - Apps that read a small number of items more frequently than others
This DynamoDB enhanced feature provides a fully managed in memory cache that runs in a cluster
enhanced
DynamoDB Accelerator (DAX)
What do DynamoDB Transactions let you do?
Query multiple tables at once and is an all-or-nothing approach
In DynamoDB, How do you calculate RCU?
Strong = (KB p.item) / 4 * (desirable RCU)
Eventual = ((KB p.item) / 4 * (desirable RCU)) /2
In DynamoDB, How do you calculate WCU?
(KB) * Desired
- round 1.5kb to 2kb
- round 500bytes to 1kb
In DynamoDB
If you don’t need DAX, please consider…
ElastiCache
ɪˈlæstɪ-kæʃ
In DynamoDB
aws dynamodb
- It returns a set of attributes for new item with given primary key
- It creates a new item (If the id exists, it replaces the old element)
- It edits an existing item’s attributes
- It returns the attributes of one or more items from one or more tables (Up tp 16mb and 100 items)
- It puts or deletes multiple items in one or more tables (25 put or delete requests)
- It adds a new table to your account
- It modifies the provisioned throughput settings, secondary index
- It Deletes a table and all of its items
- A synchronous operation that atomically retrieves multiple items from one or more tables (25 objects < 4mb)
- A synchronous write operation that groups up to 25 action requests
- It finds items based on primary key values
- It returns one or more items and items attributes by accessing every item
> get-item > put-item > update-item > batch-get-item > batch-write-item > create-table > update-table > delete-table > transact-get-items > transact-write-items > query > scan
What is Dynamo DB?
What are its 13 elements?
- It’s a key-value and document NOSQL database
- Consistency types (Eventually…)
- Data types (Binary, Number, String)
- Tables anatomy (Items, attributes)
- Partitions
- Types of Primary Key (Simple, composite)
- Global tables
- Transactions (TransacGetItems…)
- Streams (Trigger lambda functions)
- Secondary indexes (GSI, LSI)
- Types of operation searches (Query, Scan)
- Capacity Modes (Provisioned, On-Demand)
- Calculate reads and writes
- DAX
How do you reduce the frequency of failed requests to avoid ProvisionedThroughputExceeded on DynamoDB?
Error Retries and Exponential Backoff.
The idea behind exponential backoff is to use progressively longer waits between retries for consecutive error responses. You should implement a maximum delay interval, as well as a maximum number of retries. The maximum delay interval and maximum number of retries are not necessarily fixed values, and should be set based on the operation being performed, as well as other local factors, such as network latency.
In order to give you the ability to retrieve data from your DynamoDB tables more rapidly you need to use:
Two elements in the answer
- Parallel Scans
- limiting the rate