Database Specialty - DynamoDB Flashcards
Tool for Backup and restore
PITR
Terminology DynamoDB
Tables, Items, Attributes, Primary Keys, Local Secondary Indexes, Global Secondary Indexes
Data Types in DynamoDB
Scalar, Set, Document
Important points Read Consistency
Strong, Eventual and Transacional
Points Write Consistency
Standard and Transacional
Modes Pricing Model
Provisioned and On-Demand Capacity
Types of caches in DAX
Item Cache and Query Cache
Scaling Options
Automatic, Provisioned, Global Replication, Burst Capacity, On-Demand Capacity
Amazon DynamoDB – Overview Points
- Non-relational Key-Value store
- Fully Managed, Serverless, NoSQL database in the cloud
- Fast, Flexible, Cost-effective, Fault Tolerant, Secure
- Multi-region, multi-master database (Global Tables)
- Backup and restore with PITR (Point-in-time Recovery)
- Single-digit millisecond performance at any scale
- In-memory caching with DAX (DynamoDB Accelerator, microsecond latency)
- Supports CRUD (Create/Read/Update/Delete) operations through APIs
- Supports transactions across multiple tables (ACID support)
- No direct analytical queries (No joins)
- Access patterns must be known ahead of time for efficient design and performance
DynamoDB Tables
- Tables are top-level entities
- No strict inter-table relationships (Independent Entities)
- You control performance at the table level
- Table items stored as JSON (DynamoDB-specific JSON)
- Primary keys are mandatory, rest of the schema is flexible
- Primary Key can be simple or composite
- Simple Key has a single attribute (=partition key or hash key)
- Composite Key has two attributes
(=partition/hash key + sort/range key) - Non-key attributes (including secondary key attributes) are
optional
Data Types in DynamoDB
- Scalar Types
- Exactly one value
- e.g. string, number, binary, boolean, and null
- Keys or index attributes only support string, number and binary scalar types
- Set Types
- Multiple scalar values
- e.g. string set, number set and binary set
- Document Types
- Complex structure with nested attributes
- e.g. list and map
AWS Global Infrastructure
- Has multiple AWS Regions across
the globe - Each region has one or more AZs
(Availability Zones) - Each AZ has one or more
facilities (= Data Centers) - DynamoDB automatically
replicates data between multiple
facilities within the AWS region - Near Real-time Replication
- AZs act as independent failure
domains
DynamoDB Consistency
- Read Consistency: strong consistency, eventual consistency, and transactional
- Write Consistency: standard and transactional
- Strong Consistency
- The most up-to-date data
- Must be requested explicitly
- Eventual Consistency
- May or may not reflect the latest copy of
data - Default consistency for all operations
- 50% cheaper than strong consistency
- May or may not reflect the latest copy of
- Transactional Reads and Writes
- For ACID support across one or more
tables within a single AWS account and
region - 2x the cost of strongly consistent reads
- 2x the cost of standard writes
- For ACID support across one or more
Strongly Consistent Read vs Eventually Consistent Read
- Eventually Consistent Read: If we read just
after a write, it’s possible we’ll get
unexpected response because of replication - Strongly Consistent Read: If we read just
after a write, we will get the correct data - By default: DynamoDB uses Eventually
Consistent Reads, but GetItem, Query &
Scan provide a “ConsistentRead” parameter
you can set to True
DynamoDB Pricing Model - Provisioned Capacity
- You pay for the capacity you provision
(= number of reads and writes per second) - You can use auto-scaling to adjust the
provisioned capacity - Uses Capacity Units: Read Capacity Units
(RCUs) and Write Capacity Units (WCUs) - Consumption beyond provisioned capacity may
result in throttling - Use Reserved Capacity for discounts over 1 or
3-year term contracts (you’re charged a one- time fee + an houtly fee per 100 RCUs and
WCUs
DynamoDB Pricing Model - Provisioned Capacity - On-Demand Capacity
On-Demand Capacity
* You pay per request (= number of read and
write requests your application makes)
- No need to provision capacity units
- DynamoDB instantly accommodates your
workloads as they ramp up or down - Uses Request Units: Read Request Units and
Write Request Units - Cannot use reserved capacity with On-Demand mode
DynamoDB Throughput - Provisioned Capaciy mode
- Uses Capacity Units
- 1 capacity unit = 1 request/sec
- RCUs (Read Capacity Units)
- In blocks of 4KB, last block always rounded up
- 1 strongly consistent table read/sec = 1 RCU
- 2 eventually consistent table reads/sec = 1 RCU
- 1 transactional read/sec = 2 RCUs
- WCUs (Write Capacity Units)
- In blocks of 1KB, last block always rounded up
- 1 table write/sec = 1 WCU
- 1 transactional write/sec = 2 WCUs
DynamoDB Throughput - On-Demand Capacity mode
- Uses Request Units
- Same as Capacity Units for calculation purposes
- Read Request Units
- In blocks of 4KB, last block always
rounded up - 1 strongly consistent table read request = 1 RRU
- 2 eventually consistent table read request = 1 RRU
- 1 transactional read request = 2 RRUs
- In blocks of 4KB, last block always
- Write Request Units
- In blocks of 1KB, last block always rounded up
- 1 table write request = 1 WRU
- 1 transactional write request = 2 WRUs
Provisioned Capacity - Points
- Typically used in production environment
- Use this when you have predictable traffic
- Consider using reserved capacity if you
have steady and predictable traffic for
cost savings - Can result in throttling when
consumption shoots up (use auto-scaling) - Tends to be cost-effective as compared
to the on-demand capacity mode
On-Demand Capacity Mode
- Typically used in dev/test environments
or for small applications - Use this when you have variable,
unpredictable traffic - Instantly accommodates up to 2x the
previous peak traffic on a table - Throttling can occur if you exceed 2x
the previous peak within 30 minutes - Recommended to space traffic growth
over at least 30 mins before driving
more than 2x
Example 1: Calculating Capacity Units
Calculate capacity units to read and write a 15KB item
- RCUs with strong consistency:
- 15KB/4KB = 3.75 => rounded up => 4 RCUs
- RCUs with eventual consistency:
- (1/2) x 4 RCUs = 2 RCUs
- RCUs for transactional read:
- 2 x 4 RCUs = 8 RCUs
- WCUs:
- 15KB/1KB = 15 WCUs
- WCUs for transactional write:
- 2 x 15 WCUs = 30 WCUs
Example 2: Calculating Capacity Units
Calculate capacity units to read and write a 1.5KB item
- RCUs with strong consistency:
- 1.5KB/4KB = 0.375 => rounded up => 1 RCU
- RCUs with eventual consistency:
- (1/2) x 1 RCUs = 0.5 RCU => rounded up = 1 RCU
- RCUs for transactional read: * 2 x 1 RCU = 2 RCUs
- WCUs: * 1.5KB/1KB = 1.5 => rounded up => 2 WCUs
- WCUs for transactional write:
- 2 x 2 WCUs = 4 WCUs