Courses / Databases for Backend Interviews / Chapter 25
Module 11 · NoSQL and choosing a database · Chapter 25 of 27
Modelling for a Key-Value Store: DynamoDB Keys, Indexes and Transactions
Builds on Partitioning and Sharding: Partition Keys, Routing and Resharding and NoSQL Data Models: Key-Value, Document, Wide-Column and Graph. Next up: Choosing a Database: Matching Workloads to Relational and NoSQL Stores.
Part 1 · Tables, items and keys: Query, Scan and pages
What a DynamoDB table is
A chat app stores tens of lakhs of messages and must open any conversation quickly, however large the total grows. Amazon DynamoDB is a managed key-value and document database built for that shape of problem.
A table holds items, which are collections of attributes. Every item is found by its primary key, and there are two kinds. A simple primary key is a partition key alone. A composite primary key is a partition key plus a sort key. DynamoDB spreads items across physical partitions and keeps the items that share one partition key value together, in sorted order by sort key. The guide calls the group of items that share one partition key value an item collection. An item can be at most 400 KB, according to the developer guide.
Reads come in three shapes. GetItem reads one item and needs the whole primary key: both parts when the table has a sort key. Query reads from one partition: it needs the partition key name and a single value for it, an equality condition, and can add one condition on the sort key. Scan reads the whole table. Anything else that sounds like a question, "all messages from Ravi", is not a read shape the table offers, which is the subject of the next lessons.