Cheatsheet
The Basics of DynamoDB
DynamoDB is a fully managed NoSQL key/value and document database. DynamoDB is suited for workloads with any amount of data that require predictable read and write performance and automatic scaling from large to small and everywhere in between.
DynamoDB scales up and down to support what ever read and write capacity you specify per second in provisioned capacity mode. Or you can set it to On-Demand mode and there is little to no capacity planning.
- DynamoDB stores 3 copies of data on SSD drives across 3 AZs in a region.
- DynamoDB's most common datatypes areB(Binary),N(Number), andS(String)
- Tables consist ofItems(rows) and Items consist ofAttributes(columns)
Reads and Writes Consistency
DynamoDB can be set to supportEventually Consistent Reads(default) andStrongly Consistent Reads on a per-call basis.
Eventually consistent reads data is returned immediately but data can be inconsistent. Copies of data will be generally consistent in 1 second.
Strongly Consistent Readswill always read from the leader partition since it always has an up-to-date copy. Data will never be inconsistent but latency may be higher. Copies of data will be consistent with a guarantee of 1 second.
Partitions
A Partition is when DynamoDB slices your table up into smaller chunks of data. This speeds up reads for very large tables.
DynamoDB automatically creates Partitions for:
- Every 10 GB of Data or
- When you exceed RCUs (3000) or WCUs (1000) limits for a single partition
- When DynamoDB sees a pattern of a hot partition, it will split that partition in an attempt to fix the issue.
DynamoDB will try to evenly split the RCUs and WCUs across Partitions
Primary Key Design
Primary keys define where and how your data will be stored in partitions
The Key schema can be made up of two keys:
- Partition Key (PK) is also known asHASH
- TheSort Key (SK) is also known asRANGE
When using the AWS DynamoDB API eg. CLI, SDK they refer to the PK and SK by their alternative names due to legacy reasons.
Primary key comes in two types:
- SimplePrimary Key (Using only a Partition Key)
- CompositePrimary Key (Using both a Partition and Sort Key)
Key Uniqueness is as follows:
- When creating a Simple Primary Key the PKvalue may be unique
- When creating a Composite Primary Keythe combined PK and SK must be unique
When using a Sort key, records on the partition are logically grouped together in Ascending order.