Build an Application Using a NoSQL Key-Value Data Store

GETTING STARTED GUIDE

Module 1: Application overview

Learn about the details of the application, and how we can model a DynamoDB table to fit the requirements

Introduction

As mentioned at the start of this tutorial, you will be building an online bookstore application with a large product catalog. When a user accesses this application, it will showcase books that are in stock and basic information about those books, such as author, title, category, and more.

The application should be able to retrieve a specific book by a combination of its title and author so a user can get additional information about the book. The application should also allow users to view all books in a given category, such as history or biography, to allow for discoverability of books in the catalog. These books can also come in different formats, such as hardcover, paperback, and audiobook. These formats can be updated over time.

In this module, you will walk through key terminology and concepts for this application and how to model a DynamoDB table to accommodate the needs of the application.

Terminology and concepts

The following DynamoDB concepts play a key role in this tutorial:
 
  • Table: This is simply a collection of data. A table is specifically the structure in which DynamoDB stores this data. In our case, we will have a books table to store our product catalog.
  • Item: A single data record in a DynamoDB table. It is comparable to a row in a relational database. Each item in our table will correspond to a book in our product catalog.
  • Attribute: A single data element of an item. It is comparable to a column in a relational database. However, unlike columns in a relational database, attributes do not need to be specified at table creation, other than the primary key. Attributes for us will consist of elements such as Title, Author, and Category.
  • Primary key: A primary key is a unique identifier for a single item in a DynamoDB table. When you create a table, you must specify the primary key name and type. The primary key uniquely identifies each item written to a table. A simple primary key consists of a single attribute, and a composite primary key consists of two attributes. For example, we will be using a combination of the Title and Author as the unique identifier for each book.
  • PartiQL: This is a SQL-compatible query language that enables you to codify your DynamoDB data operations using SQL syntax.

 Time to Complete

15 minutes

 Prerequisites

  • An AWS account: if you don't already have one, follow the Setting Up Your Environment getting started guide for a quick overview.
  • An installed version of the AWS SDK via pip install boto3

Data model

When building an application, you should always take time to design the data models needed in your application logic. The data model design should consider the data access needs of your application, both for reading and writing data.

DynamoDB is a nonrelational database, which means you don't need to specify the full schema upfront when creating a table. You only need to declare the primary key for your table, which uniquely identifies each record in your table. This reduces the upfront cost of designing your data model because you can easily modify your schema as your application’s needs change.

As mentioned earlier, your application needs to retrieve an individual book by its title and author. Because the combination of title and author is a unique identifier of a book, you can use those attributes as the primary key of your table. Your application also needs to store information about the category of our book, such as history or biography, as well as the available formats of your book—hardcover, paperback, or audiobook—that are mapped to the item numbers in your inventory system.

Visualization breaking down
With these needs in mind, you can use the following schema for your table:
  • Title (a string): The title of the book
  • Author (a string): The author of the book
  • Category (a string): The category of the book, such as history, biography, or sci-fi
  • Formats (a map): The different formats that you have available for sale (such as hardcover, paperback, and audiobook) and their item numbers in your inventory system

In the following steps, you create the table by specifying the composite primary key (Title and Author) of your table. Then, you load some items into your table and read individual items from the table.

Conclusion

In this module, we covered key terminology and concepts and how to model a DynamoDB table to accommodate the needs of the application.

Up Next: Inserting and retrieving data

Was this page helpful?