What is AWS Dynamo DB?
Introduction to Dynamo DB:
AWS Dynamo DB is a No SQL Database which is built to support No SQL compatible database in cloud environment. AWS Dynamo DB is fully managed server less No SQL database service it means you do not need to take care of any server/infrastructure, AWS does take care it for you.
Dynamo DB is highly salable,available and durable database service. it is a key value pair database store. Dynamo DB can also store document. You can store any amount of data within dynamo DB table as it scale automatically.
Dynamo DB has been designed to provide single digit milliseconds latency to end users.
Dynamo DB automatically replicate data in multiple availability zone within a single reason to make data highly available in case of failure of any one of the availability zone.
Dynamo DB also provides global table to replicate tables in a different region for disaster recovery. Global tables can also help reducing the latency to end users spread across multiple regions.
Dynamo DB pricing work on pay as you go model, DynamoDB charges for reading, writing, and storing data in your DynamoDB tables.
Dynamo DB provide two capacity mode
- On-demand capacity mode: With on-demand capacity mode, DynamoDB charges you for the data reads and writes your application performs on your tables. You do not need to specify how much read and write throughput you expect your application to perform because DynamoDB instantly accommodates your workloads as they ramp up or down
- provisioned capacity mode: With provisioned capacity mode, you specify the number of reads and writes per second that you expect your application to require. You can use auto scaling to automatically increase or decrease the read and write capacity
Dynamo DB can be used for various application types
- Internet of Things (IoT)
- Mobile applications
- Web applications
- Game development
- Social networking
Below diagram explain use of Dynamo DB for simple web application.
How Dynamo DB works:
In DynamoDB, tables, items, and attributes are the main components we have to work. A table is a collection of items and every item is a collection of attributes.
DynamoDB uses primary keys for identifying uniquely each item in a table.. Dynamo DB also uses secondary indexes for additional querying flexibility . You can use DynamoDB Streams to capture modification of items in DynamoDB tables.
Items in DynamoDB are similar in many ways to rows, records, or tuples in other database systems.You can store any number of items in DynamoDB DB there is no limit for that. This is the scalability of Dynamo DB to grow database to ant size.
Attributes in DynamoDB are similar to fields or columns in other database systems like columns in RDBMS.
You can either use AWS Command Line Interface or AWS Console to work with Dynamo DB table.
You can write application code in the various AWS SDKs to interact with DynamoDB.
The AWS SDKs provide support for DynamoDB in various languages like Java, JavaScript in the browser, .NET, Node.js, PHP, Python, Ruby, C++, Go, Android, and iOS.
When you create a table, along with the table name, you must specify the primary key of the your table.
DynamoDB supports two kinds of primary keys:
Partition key – A simple primary key, composed of one attribute.Example employee id can be partition key in employee table.
Partition key and sort key – A composite primary key, this type of key is composed of two attributes. These two are partition key and sort key.
DynamoDB uses the partition key’s value as input to an hash function internal to Dynamo DB structure. The output from this hash function determines the partition where the item will get stored.
Example Employee id can be partition key and Employee name can be sort key in employee table
AWS DynamoDB create-table command to create table using AWS CLI
DynamoDB provides four operations for basic create, read, update, and delete functionality:
PutItem — Create an item.
GetItem — Read an item.
UpdateItem — Update an item.
DeleteItem — Delete an item.
Consistency Model:
DynamoDB provides two consistency models. you can use any of them according to your need. However Eventually Consistent is best suitable for most of the applitions. It is suitable for Web services, Mobile applications, Storing S3 file location in dynamo DB, Gaming applications etc.
Eventually Consistent Reads-
When you read data from a DynamoDB table,the response might not return recently written data as it takes some time to complete write operation. The response might include some stale/outdated data. If you repeat your read request after a short time, the response should return up-to-date data.
Strongly Consistent Reads-
When you read data from a DynamoDB table, DynamoDB returns a response with the most up-to-date data, reflecting the updates from all prior write operations that were successful. However, this consistency comes with some disadvantages:
By default Dynamo DB uses eventually consistent reads. Strongly consistent reads have little higher latency than eventually consistent reads
Choosing the right capacity mode for your application:
Choose On-demand capacity mode for below kind of workloads
Create new tables with unknown workloads.
Have unpredictable application traffic.
Prefer the ease of paying for only what you use.
Choose provisioned capacity mode for below kind of workloads
Have predictable application traffic.
Run applications whose traffic is consistent or increase gradually.
Can forecast capacity requirements to control costs.
Global Tables:
Amazon DynamoDB global tables provide a fully managed solution for deploying a multi regional tables for your application , So you do not need to write any custom replication solution for your application.
when using global tables you can specify the AWS Regions where your table needs to be replicated. DynamoDB automatically take cares of the necessary tasks to create identical tables in these Regions and propagate ongoing data changes to all of them.
DynamoDB Streams:
A DynamoDB stream is an flow of capturing information for items modification in a DynamoDB table. Once you enable a stream on a table, DynamoDB captures information about every modification to data items in the table.
You can enable a stream on a new table during creation of table. You can anytime enable or disable a stream on an existing table later.
Items can be available in Dynamo DB stream for up to 24 hours. Items availability can be controlled through time to live(TTL). once TTL is expired items can be deleted from stream.
DynamoDB Streams is useful when you want to replicate data to other regions and other AWS services needs to read data from Dynamo DB.
For example AWS Lambda, AWS Kinesis etc.
You can invoke synchronously AWS Lambda function once items is modified in DynamoDB table. AWS Lambda can poll on dynamo DB stream and get the items details and then perform any actions for the items such as passing information to AWS services S3, Kinesis, SQS, SNS etc.
DAX
Dynamo DB provide an Accelerator (DAX) to support in-memory cache for frequent items. As Dynamo DB provide single digit milliseconds latency, DAX can be used to achieve faster response like in microseconds.
DAX can help in reducing the cost as it reduce read operation on Dynamo DB hence reducing read capacity unit to save cost of read provisioned capacity.
Backup and Restore
DynamoDB offers two methods to back up your table data.
Continuous backups with point-in-time recovery (PITR) provide an ongoing backup of your table for the preceding 35 days.
You can enable point-in-time recovery(PITR) from AWS Management Console, AWS Command Line Interface, and the DynamoDB API. When enabled, point-in-time recovery(PITR) provides continuous backups until you explicitly disable it.
On-demand backups create snapshots of your table to archive for long time retention. which can be used to restore your table.
You can back up and restore your table data anytime from the AWS Management Console or with a single API call.
Security:
Data protection:
Security is the highest level priority in any cloud environment and it should not be compromised in any case. AWS Dynamo DB provide security by protecting your data. Dynamo DB protects data stored in tables by providing encryption at rest and protects in flight data between on-premises clients and Dynamo DB, and between Dynamo DB and other AWS services by providing encryption in transit.
you can store sensitive data in Dynamo DB, all data stored in dynamo DB are encrypted at rest using encryption key stored in AWS key management service(KMS).AWS Dynamo DB integrate with AWS KMS service seamlessly to encrypt and decrypt data.
Accessibility to Dynamo DB
Dynamo DB integrate with AWS Identity and Access Management (IAM) service to secure access for limited IAM identities. Your IAM administrator can control by providing access to only required users, groups, roles for AWS services to Dynamo DB and DAX.
Create user/groups and assign proper policy like create table, delete table, get items, put items etc.
To access Dynamo DB from other services, you can create role and assign that role to service which need access for Dynamo DB.
Example if Lambda function only need read access on Dynamo DB then you can create role with policy having permission like GetItems and attach the role to Lambda function
Inserting bulk data into Dynamo DB.
You can ingest bulk data into dynamo DB from S3. Data can reside in CSV file in S3. Lambda fucntion can have logic to get data from S3 and upload into Dynamo DB.
Configure your S3 bucket with an event trigger for lambda function So once CSV file is uploaded into S3 bucket Lambda function will be invoked and ingest that CSV file data into Dynamo DB.
you can transform data from RDBMS to Dynamo DB with help of AWS Glue which AWS ETL service.
Dynamo DB Pricing:
DynamoDB charges one write request unit for each write and two write request units for transactional writes.
For reads, DynamoDB charges one read request unit for each strongly consistent read (up to 4 KB), two read request units for each transactional read, and one-half read request unit for each eventually consistent read
Write request units $1.25 per million write request units
Read request units $0.25 per million read request units
You do not need to provision storage: DynamoDB monitors the size of your tables continuously to determine your storage charges. Dynamo DB charge $0.25 per GB-month, However you can utilize first 25 GB per month free. after 25 GB Dynamo DB start charging for storage.
for continuous backup you need to pay $0.20 per GB per month
for on-demand backup you need to pay $0.10 per GB per month
Data Transfer charges: Data transfer in and out refer to transfer into and out of DynamoDB. DynamoDB does not charge for inbound data transfer, and it does not charge for data transferred between DynamoDB and other AWS services within the same AWS Region.
Data transferred across AWS Regions is charged on both sides of the transfer. data transfer cost is $0.09 per GB per month.
Final Words – Dynamo DB
I hope after reading this article you get a better understanding of AWS Dynamo DB basics and it’s capabilities. It is very inexpensive service with many features as described above.
I wish you all the best knowing more about AWS. If you need to know about other AWS services you can go through other articles posted site. Thanks for spending some time reading the article !!