AWS
Aniket Kulkarni  

AWS DynamoDB Basics

DyanmoDB is a fully managed NoSQL database service. There are a lot of great features provided by AWS. It is very fast and highly scalable. Performance up to single-digit milliseconds latency, given that partition key, is designed very well. There is no need to worry about the storage space. It comes with an unlimited storage option. Storage is rates are very cheap. Stored data is highly available, as it is automatically replicated to multiple AZs.

Features

  • NoSQL database – supports key-value and Document data models.
  • Serverless – means highly available.
  • Unlimited storage – supports petabyte of data.
  • Very fast – single digit milliseconds latency.
  • Global table – allows replication to multiple regions around the globe.
  • Scaling options – On-demand or Auto scale.
  • Change capture – AWS Lambda integration to provide triggers.
  • Security – encryption at rest.

Components

  1. Table
  2. Item
  3. Attribute
  4. Partition Key
  5. Sort Key
  6. Secondary Indexes
  7. Storage

1. Table

  • Table is a way to organize related data together.
  • Same as any table in the relational databases, difference is storing the data.
  • DynamoDB supports Global tables
    • Real time update in one region reflects data in the other region.
    • Good way to maintain the integrity across all the regions where you operate.
    • For example: Products catalogue across the globe

2. Item

  • An Item is similar to a row, record in relational databases.
  • It is a group of attributes that is uniquely identifiable among all of the other items.
  • Table can contain zero or more items.
  • No limit to store the number of items in a table.
  • For exmaple: In Products table each product represts an item.

3. Attribute

  • An Attribute is similar to a column or field in relation database.
  • It is fundamental data element coposed of one or more attributes.
  • For example: Products table contains atrributes such as ProductId, ProductName, ProductDescription, etc.

4. Partition Key

  • Primary key of a table composed of one attribute.
  • No two items can have same partition key, as it is unique.
  • This is very critual when designing the DynamoDB table.
  • When migrating from SQL databases such as MySQL or Oracle
    • First identify the access patterns of your data. Identifying access patterns makes easier to decide the partition key.
    • Since DynamoDB is NoSQL database, data can be accessed only using partition key or sort key
  • Example is ProductId from products table

5. Sort Key (Range Key)

  • This is called Composite key.
  • Key is composed of two attributes, first attribute is partition key and second attribute is sort key.
  • How does it work?
    • DynamoDB uses the partition key value as input to an internal hash function.
    • The output from the hash function determines the partition (physical storage internal to DynamoDB) in which the item will be stored.
    • All items with the same partition key value are stored together, in sorted order by sort key value.
  • Two items can have same partition key but must have different sort keys.

6. Secondary Indexes

  • Secondary indexes allow to query the data in table using an alternate key. Alternate key is different from primary key of the table.
  • There are two types of Secondary indexes:
Global Secondary Index Local Secondary Index
a. Partition key and sort key can be different from table. a. Partition key must be same, can have different sort key.
b. Default quota of 20 Global secondary indexes per DDB table.b. 5 Local secondary indexes per DDB table.
Global Secondary Index vs Local Secondary Index

7. Storage

  • No need to provision storage.
  • Storing data is very cheap. Example for Ohio region:
    • First 25 GB stored per month is free.
    • $0.25 per GB-month thereafter.
  • Base table items and Global secondary index attributes sums the total storage of the table.

AWS is continuously improving its services. It keeps updating the limits for the region. So, I haven’t talked much about limits. It is always better to refer to official AWS documentation for limits (Tables, Global tables, Global Secondary Indexes, Local Secondary Indexes, etc).