DynamoDB

Table of contents
  1. Local Setup
  2. NoSQL Workbench for DynamoDB
  3. Key design / Data model
    1. Primary Key
    2. Design
  4. Itty Bitties

Local Setup

Detailed documentation is provided here. Docker option is available as well.


NoSQL Workbench for DynamoDB

This will be a great lifesaver while designing data models and testing connection. You can download it here.


Key design / Data model

If you are used to relational database schemas, it is easy to end up designing your database to use multiple tables, to structure logical joins using foreign key-like attribute and what not, or to use multi-level nested structure.

However, in NoSQL, all these familiar patterns are not only inefficient, but also almost impossible to manage.

There really is no such thing as a schema design in DynamoDB but a careful design of primary key is useful.

Primary Key

There are two types of keys that can consist a primary key in DynamoDB: partition (hash) key and sort (range) key.

A primary key could just consist of a partition key or be a compound of partition and sort key.

Because each item is identified by a unique primary key, you must use a unique partition key if your primary key only consists of it.

However, if you also use the sort key, the partition key may overlap but the sort key must be unique.

Partition key and sort key are also called hash and range keys.

The naming indicates that the partition key serves as a hashed index to a physical storage internal unit called a partition.

The sort key sorts the items within a partition into groups of similar items, effectively providing an efficient way to query for a range.

Hence, design of primary key has an impact on the performance of the DB.

Design

In relational databases, primary keys are usually a single attribute (like StudentID) of a homogeneous type.

However, in DynamoDB it is common to use a multi-purpose (or heterogeneous) key attributes.

Typically, every item is given an attribute called PK and SK for partition and sort key.

This way the key attributes may contain any information without restriction.


Itty Bitties

  • Compared to SQL statements, querying in DynamoDB can be a real pain in the ass…