DynamoDB is a database service provided by Amazon. Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. You can use it to store and retrieve any amount of data without worrying about hardware provisioning, setup & configuration, replication, software patching, or cluster scaling. It mostly takes care of these things itself while also providing options to configure these things manually.
DynamoDB provides good replication and traffic handling. It distributes our data on multiple servers within the availability zones in an AWS region and stores the data on Solid State Disks (SSDs). These availability zones are linked to each other with fast and inexpensive connectivity while also being isolated from each other, meaning when one availability zone goes down for some reason, it won’t affect any other zone and thus our data will be highly available to us. Our data is spread across multiple servers which provides us with good traffic handling and handles our throughput and storage requirements.
Now, let’s look at the core components of DynamoDB.
Core Components of DynamoDB
The core components of DynamoDB are tables, items, and attributes. Tables are a collection of items and items are a collection of attributes. To make it analogous to a SQL table, tables are tables, an item is a row in a table, and attributes are columns of the table. Let’s look at them one by one.
A table is a collection of data. All the data is stored in DynamoDB tables. Following is an example of a table storing information about cars and their owners.
Items are analogous to rows in a SQL table. An item represents uniquely identifiable data in the table. Looking at the above example diagram, the table consists of three items. Each item is uniquely identifiable using the attribute “License_Number”. Each item represents a single car and it’s owner. A table is nothing but a collection of multiple items. In dynamoDB, there is no limit to the number of items you can store in a table.
Attributes are analogous to columns in a SQL table. An attribute represents a particular information about an item. For example, in the above car owner table, attribute “Owner_First_Name” represents the first name of that car owner, “Owner_Last_Name” represents the last name of that car owner. An item in a dynamoDB table is nothing but a collection of attributes. DynamoDB supports nested attributes, for example, in the above table, the third item consists of a nested attribute namely “Owner_Address”. A table can consist of nested attributes up to 32 levels deep.
Notice that DynamoDB is schema-less, meaning that it doesn’t need to have any attributes except key-schema(partition key and sort key, explained below). Its items may have some attributes and some not, that is they may have a different number of attributes.
Partitioning Data in DynamoDB
To understand the partitioning strategy of DynamoDB, let’s look at the ways of defining a primary key on the table.
Partition Key – Partition key is nothing but a single attribute that uniquely identifies an item of a dynamoDB. The partition key is also referred to as a hash attribute. In a table with only a partition key, no two items can have the same partition key value. The value of partition key is used as an input to an internal hash function by DynamoDB and it’s output tells it on which partition(physical storage internal to DynamoDB) to store the item containing that attribute. While searching for the item, again the value of this attribute is used as an input to the hash function to determine on which partition is the item stored. Partition key can only be scalar, meaning that it can only hold a single value. The only allowed data types for a partition key are the string, number, or binary.
Partition Key and Sort Key – This is also referred to as a composite primary key. It is composed of two attributes, the first attribute is a partition key and the second attribute is a sort key. We have already discussed partition key and how it works. A sort key comes into picture after the item’s partition is decided. Sort key, also known as range key, helps in storing the items on the same partition in a sorted order. If a table has a composite primary key, it is possible for items to have the same value of partition key, but then their sort key value must be different. So, same partition key means the items will be stored in the same partition and sorted key will decide the order in which they are stored. Composite primary key provides extra flexibility when querying for data. For example, you can just provide a partition key and get all the records for that partition key value, or you can provide a partition key and a range of sort key values to get a subset of the records with given partition key.
This will be all for this blog. In my upcoming blogs, I will be talking more about DynamoDB, setting up a DynamoDB table, and connecting your application with DynamoDB.
Thanks for reading!
1 thought on “Introduction to AWS DynamoDB4 min read”
Reblogged this on .
Comments are closed.