DynamoDb is a NoSQL database, which to me means it’s schema-less, scales horizontally, and has incredible performance when accessing data via K/V pairs. I’m adding this here as writing about it helps me remember.
- Two types of primary key
- Partition key
- same as a primary key
- must be unique scalar attribute
- internally also known as a hash attribute, because of the internal hash function (e.g. EmployeeId)
- tells what “partition” the item will be stored at
- Parition key and Sort key
- same as a composite primary key
- the partition key is not unique, but becomes unique when combined with the sort key (e.g. Artist & Song)
- sort key is internally also known as a range attribute
- partition tells where it is and sort key sorts the item
- Partition key
- Secondary index
- use when you want to query using an alternate key in addition to the partition key
- creating an index “projects” your chosen attributes, from the base table, into a data structure
- Two types of secondary index
- Global secondary index
- an index of either (1) a partition key only or (2) a composite (partition & sort), that can be different than the table’s
- spans all partitions
- can only have 5 indexes
- no size restriction of all indexed
- eventual consistency
- can be added/deleted even after table creation
- Local secondary index
- same partition key as the table’s, but with a different sort key
- spans only one table based on the partition key of the table
- can only have 5 indexes
- 10 GB or less in size for all indexed
- eventual or strong consistency
- cannot be added/deleted after table creation
- Global secondary index
- DynamoDb Streams
- perfect for DB cross-replication
- must be turned on for a table
- each event is a stream record
- TTL of 24 hours
- can be used with AWS Lamdba to create trigger (e.g. send “Welcome” email when new stream record is received, via a new item write)