Data Model

  • DynamoDB data model include
    • Tables
    • Items
    •  Attributes
  • a table is a collection of items
  • item is a collection of one or more attributes.
  • Each item also has a primary key that uniquely identifies item.

Data Types

  • DynamoDB has flexibility with database schema
  • DynamoDB only requires a primary key attribute
  • Each item, added to table can then add additional attributes
  • Thus easily, expand schema without having to rebuild entire table.
  • Major categories in which data types fall into three major categories are – Scalar, Set, or Document.
  • Scalar Data Types:  represents exactly one value. DynamoDB supports scalar types –
  • String Text and variable length characters up to 400KB. Supports Unicode with UTF8 encoding
    • Number Positive or negative number with up to 38 digits of precision
    • Binary Binary data, images, compressed objects up to 400KB in size
    • Boolean Binary flag representing a true or false value
    • Null Represents a blank, empty, or unknown state. String, Number, Binary, Boolean cannot be empty.
  • Set Data Types –represent a unique list of one or more scalar values.  Each value in a set needs to be unique and same data type. sets do not guarantee order.  three set types
    • String Set – Represents unique list of String attributes
    • Number Set – Represents unique list of Number attributes
    • Binary Set – Represents unique list of Binary attributes
  • Document Data Types –to represent multiple nested attributes, like JSON file. two document types – List and Map, which can be combined and nested to create complex structures.
    • List –store ordered list of attributes of different data types.
  • Map –store unordered list of key/value pairs. Maps can be used to represent structure of any JSON object.

Primary Key

  • uniquely identifies each item in table
  • point to exactly one item
  • DynamoDB supports two types of primary keys, and configuration cannot be changed after a table has been created –
  • Partition Key: Has one attribute-  a partition (or hash) key. DynamoDB builds an unordered hash index on this primary key attribute.
  • Partition and Sort Key: Has two attributes – first is partition key and second one is sort (or range) key. Each item in table is uniquely identified by combination of its partition and sort key values.

Provisioned Capacity

  • During DynamoDB table creation, required to provision a certain amount of read and write capacity
  • As per configuration settings, DynamoDB will provision infrastructure capacity
  • capacity is measured in read and write capacity units.
  • CloudWatch can be used to monitor DynamoDB capacity and make scaling decisions.
  • Metrics include ConsumedReadCapacityUnits and ConsumedWriteCapacityUnits.

Secondary Indexes

  • It allows to query data in table using an alternate key other than primary key
  • table with a partition and sort key we can define secondary indexes on that table
  • Types of indexes
    • Global Secondary Index: has a partition and sort key to be different from those on table. You can create or delete a global secondary index on a table at any time.
    • Local Secondary Index: It has same partition key attribute as primary key of table, but a different sort key. You can only create a local secondary index when you create a table.

Writing and Reading Data

  • write and read items to table using indexes
  • DynamoDB provides multiple operations to create, update, and delete individual items.
  • DynamoDB has multiple querying options to
    • search a table or index
    • retrieve back a specific item or a batch of items.

Writing Items

  • DynamoDB has primary API actions to create, update, and delete items: PutItem, UpdateItem, and DeleteItem.
  • PutItem action to create new item with one or more attributes. Wwill update an existing item if primary key already exists.  only requires a table name and a primary key
  • UpdateItem action will find existing items based on primary key and replace attributes.

Reading Items

  • Read a created item by calling GetItem action or search using Query or Scan action.
  • GetItem retrieves item based on its primary key.
  • All of item’s attributes are returned by default, and then we have option to select individual attributes to filter down results.

Eventual Consistency

  • While reading items from DynamoDB, operation can be
    • eventually consistent
    • strongly consistent
  • Consistency across all copies of data is reached within a second
  • with repeat read request after a short time, response returns latest data.
  • Eventually Consistent Reads
  • Data read might not reflect results of a recently completed write operation.
  • might include some stale data
  • Strongly Consistent Reads
    • DynamoDB returns with most up-to-date data
    • reflects updates by all prior related write operations
    • might be less available during a network delay or outage

Batch Operations

  • operations for working with large batches of items
    • BatchGetItem
    • BatchWriteItem – perform up to 25 item creates or updates with a single operation

Searching Items

  • two operations to search –  Query and Scan
  • These operations can be used to search a table or an index.
  • Query  – primary search operation to find items in a table or a secondary index using only primary key attribute values. Needs a partition key attribute name and a distinct value to search. Results sorted by primary key and are limited to 1MB.

Scaling and Partitioning

  • DynamoDB is fully managed service which eases, building and scaling a NoSQL cluster
  • create tables that can scale up to hold unlimited number of items with consistent low-latency performance
  • DynamoDB table can scale horizontally by using partitions
  • Each partition represents a unit of compute and storage capacity.
  • DynamoDB decides which partition to store item in based on partition key.
  • partition key is used to distribute new item among all of available partitions

Security

  • granular control over access rights and permissions for users
  • DynamoDB integrates with IAM to provide strong control over permissions using policies.
  • create policies to allow or deny specific operations on specific tables
  • use conditions to restrict access to individual items or attributes.

DynamoDB Streams

  • DynamoDB Streams makes list of item modifications for last 24-hour period
  • extends application functionality without modifying original application
  • Streams can be enabled or disabled for DynamoDB table using
    • AWS Management Console
    • Command Line Interface (CLI)
    • SDK
  • A stream consists of stream records.
  • Each stream record is single data modification in DynamoDB table to which stream belongs.
  • Each stream record gives a sequence number, for order in which record was published to stream.
  • Stream records are organized into groups, or shards.
  • Each shard is a container for multiple stream records.
  • Shards live for a maximum of 24 hours and, with load levels, could be split before being closed.
Menu