WavebreakMediaMicro - Fotolia


Manage services with Amazon DynamoDB database tool

Amazon DynamoDB manages database administration tasks, freeing up time for developers to write code for independent distributed services that correspond to defined attributes.

The cloud is well-suited for deploying highly scalable services, especially as it pertains to distributed services....

Instead of writing monolithic applications that perform a wide range of functions, developers are turning to distributed services that perform a single, narrowly defined task. Distributed services provide an efficient way to configure and manage a range of cloud environments. And Amazon DynamoDB can be used to implement distributed services.

With the DynamoDB database tool, developers can write independent services to implement common functions, such as user authentication, access controls and user preferences. They can then use those services across applications, instead of writing a single application that implements commonly needed features. A DynamoDB database has flexible schemas, unlike relational databases, which require a predefined schema describing the structure of tables. The DynamoDB database stores JavaScript Object Notation documents within its tables; documents can vary within the same table to provide additional flexibility.

Documents about end-user preferences, for example, can have one set of attributes for end users that only access an application through a Web interface and a different set of attributes for users that prefer to work with a mobile app interface that communicates with a back-end application.

When starting out with a DynamoDB database, developers must write the services they will use. It helps to think in terms of clusters of attributes an IT team wants to track how the attributes will be implemented in different DynamoDB tables. These tables are somewhat analogous to relational tables -- both store sets of related attributes but the attributes can vary across documents in a DynamoDB database.

It is also important to plan primary keys and secondary indexes based on how a developer will query the data. With DynamoDB, developers can filter query results using expressions and comparison operators, similar to SQL queries.

DynamoDB supports full table scans across a table or using a secondary index. However, there are limits to the data returned in a single scan operation -- the current limit is 1 MB. Therefore, developers should avoid scans when possible opting instead to retrieve data based on primary key or secondary index values. For more advanced query operations, consider indexing the contents of DynamoDB documents using a data search and analysis tool, such as ElasticSearch.

Maintain DynamoDB database performance metrics

A key advantage of DynamoDB is scalability. For instance, with DynamoDB, developers do not provision EC2 instances or manage databases. Instead, they create tables and then add, modify, delete and query objects within those tables. This management method cuts back on the labor needed because AWS handles database administration tasks.

Along with defining tables, attributes, primary keys and secondary indexes, it's important to consider performance requirements. Luckily, DynamoDB is fairly flexible on this front. Developers can specify how many IOPs they want to support and can configure DynamoDB tables to support up to 10,000 reads per second and 10,000 writes per second. Developers who need higher IOPs can contact AWS to request more.

DynamoDB supports read operations classified as "strongly consistent" and "eventually consistent." It is important to take the difference between the two into account: Strongly consistent reads are charged at a higher rate than eventually consistent reads. Strongly consistent reads reflect all successful writes to a document. On the other hand, eventually consistent reads might not reflect all the latest write operations, but usually include all writes within one second of the write operations. Service developers should use strongly consistent reads only when necessary; and use eventually consistent reads when some inconsistency is tolerable.

Incorporate Lambda and Streams

DynamoDB Streams are a flow of attribute-level changes made to DynamoDB tables. Developers can use Streams like triggers in relational databases to evoke some action or computation based on a change to a DynamoDB object. For example, running AWS Lambda functions in response to DynamoDB Stream events is a common pattern. DynamoDB and Lambda will scale automatically, which reduces the risk of having a high volume of DynamoDB Stream events that can't be processed because an EC2 instance isn't configured for Auto Scaling.

DynamoDB pricing mostly comes down to a combination of throughput capacity, indexed storage and Streams. At time of publication, write throughput is charged at $0.0065 per hour for every 10 write units; read throughput is charged the same rate per hour for every 50 read units. For indexed storage, AWS offers the first 25 GB of storage free with $0.25 per GB of indexed storage per month after that. The first 2.5 million DynamoDB Stream reads are free of charge. After that, Streams requests are charged at $0.02 per 100,000 units. All rates are subject to change, depending on region.

Next Steps

Lambda and DynamoDB Streams work together

DynamoDB offers advantages in mobile app development

Track S3 objects with DynamoDB

Dig Deeper on AWS database management