Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Seven NoSQL Databases in a Week

You're reading from  Seven NoSQL Databases in a Week

Product type Book
Published in Mar 2018
Publisher Packt
ISBN-13 9781787288867
Pages 308 pages
Edition 1st Edition
Languages
Authors (2):
Sudarshan Kadambi Sudarshan Kadambi
Profile icon Sudarshan Kadambi
Xun (Brian) Wu Xun (Brian) Wu
Profile icon Xun (Brian) Wu
View More author details

Table of Contents (16) Chapters

Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Introduction to NoSQL Databases MongoDB Neo4j Redis Cassandra HBase DynamoDB InfluxDB Other Books You May Enjoy Index

Chapter 7. DynamoDB

DynamoDB is a managed NoSQL database service provided by Amazon. To use DynamoDB, you have to pay for throughput only—that is, read/write operations per second; you don't have to worry about storage, server, or other infrastructure-related issues. All infrastructure is managed by Amazon.

The following are some key features provided by DynamoDB:

  • DynamoDB spreads data and request traffic to multiple servers to provide better throughput and storage.
  • Data is stored on a solid state drive (SSD) and is replicated over multiple availability zones to provide high availability and fault tolerance.
  • It provides data backup using S3 storage.
  • It allows you to decide the expiry time of items by allowing you to set a time-to-live parameter. The item will be deleted after this time expires, which makes storage management more efficient.
  • We only have to pay for throughput, which makes DynamoDB cost effective.
  • It allows you to integrate with other Amazon services, such as the Identity and Access...

The difference between SQL and DynamoDB


DynamoDB uses the NoSQL model, which means that it is a non-relational database system. The difference between a relational database and DynamoDB is outlined in the following table:

Setting up DynamoDB


To work with DynamoDB, we have to set up an AWS account. Amazon provides local JAR support where we can test our application. Now we will look into both setups in detail.

Setting up locally

AWS provide a version of DynamoDB for local installation. It supports the creation of an application without the web services or connection. It reduces provisioned throughput, data storage, and transfers by allowing local databases. When we are ready for deployment, we can make some changes for it to be used with AWS.

To use DynamoDB locally, we have to use the .jar executable file. We can download .tar or .zip, based on the operating system we are using. For the Unix OS, we have to use .tar, and for Windows, we have to download a .zip file.

Use the following links to download the respective files:

Once...

DynamoDB data types and terminology


In DynamoDB tables, items and attributes are the core component that you work with. A table is a collection of items, and each item is a collection of attributes. DynamoDB uses the primary key to uniquely identify each item in the table and secondary indexes to fire the query more flexibly. DynamoDB also provides streams to capture data modification events in DynamoDB tables. DynamoDB has size limits on the following components—this may vary from region to region:

  • Tables, items, and attributes
  • Primary key
  • Secondary indexes
  • DynamoDB streams

In the next section, we will look at these components in detail.

Tables, items, and attributes

Similar to other database systems, DynamoDB stores data in tables. A table is a collection of data. For example, if we have a table called Person, you could use this to store personal information, contact information, information about friends and family, and other such information. You could also have a table called Cars to store...

Data models and CRUD operations in DynamoDB


To perform CRUD operations in DynamoDB, select DynamoDB from the database services in the AWS Account Service section, as shown in the following screenshot:

Once you select DynamoDB from the section, it will redirect you to the DynamoDB console, where it will show an option for creating the table:

To create a table, click on the Create table button. This will take you to the Create table screen. During the creation of the table, you have to provide the primary key, along with the table name.

Here, we are creating a table called customer, and each customer is identified by customer_id:

Once the table is created, it is listed in the console, and other operations that can be performed on the table, such as delete table, insert item, and so on, are also shown:

Here, we can select the table from the list of created tables and click on the Delete table button to delete the table.

If you want to list events on the table, you can click the Manage Stream button...

Limitations of DynamoDB


DynamoDB has size limits on its components, described in the following list. This may vary from region to region:

  • Capacity unit:
    • One read capacity unit = one strongly consistent read per second or two eventually consistent reads per second, for items up to 4 KB in size
    • One write capacity unit = one write per second for items up to 1 KB in size
  • Table size: There is no practical limit on table size. Tables are unconstrained for the number of items and number of bytes. But for any AWS account, there is an initial limit of 256 tables per region. To increase the limit, you have to raise the request.
  • Secondary indexes: You can define a maximum of five local secondary indexes per table. You can project up to 20 attributes into all of the table's local and global secondary indexes. These should be used to define the attributes. While creating the table operation, if you specify the ProjectionType of INCLUDE, then the number of NonKeyAttribute for all of the secondary indexes...

Best practices


To work with DynamoDB more efficiently, we should follow some best practices while designing tables and items:

  • Table best practices: DynamoDB tables are distributed across multiple partitions. For the best results, design your tables and applications so that read and write activities are spread evenly across all the items on your table, and avoid I/O hotspots that can degrade the performance of your application:
    • Design for uniform data access across items in your table
    • Distribute the write activity during data upload operations
    • Understand the access platform for the time series data
  • Item best practices: DynamoDB items are limited in size. However, there is no limit to the number of items in the table. Instead of storing large attribute data values in an item, consider the following alternative for your design:
    • Use one-to-many tables instead of a large set of attributes
    • Use multiple tables to support a varied access pattern
    • Compress large attribute values
    • Store large attribute values...

Summary


DynamoDB, a NoSQL database provided by Amazon, is an alternative to many other NoSQL databases, such as MongoDB. It provides an easy interface, using the console to create the table and perform related operations through the console. Amazon provides a large set of language-specific SDKs and APIs to interface with various programming languages. Thus, DynamoDB is becoming more popular day by day.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Seven NoSQL Databases in a Week
Published in: Mar 2018 Publisher: Packt ISBN-13: 9781787288867
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}

SQL

DynamoDB

The SQL database system uses the persistent connection and SQL commands.

DynamoDB uses HTTP/HTTPS requests and API operations.

RDBMS's fundamental structure is a table, and its schema must be defined in advance before any operation happens on a table.

DynamoDB uses the primary key, and a schema is not required to be defined in advance. It also uses various data sources.

All table information is accessible and we can query almost all data. SQL is rich in query processing.

Only the primary key is available for querying. To get more flexibility in querying data, one must use secondary indexes.

In RDBMS, information is stored in rows of tables.

In DynamoDB, information is stored as items in a table and the item structure can vary as it is schemaless.

SQL databases use a select...