- [Adam] Hi, welcome back. In this portion of the class, we're discussing the serverless NoSQL solution on AWS called Amazon DynamoDB. Together, we will discover how DynamoDB service stores data, sorts, and completes scans and queries. Amazon DynamoDB makes your life easier by offering a simple and cost-effective way to store and retrieve any amount of data and serve any level request of traffic. Listen, we are talking about millions and millions of requests here. It's important to understand the foundational concepts of DynamoDB, such as partition keys and sort keys, as well as local and global secondary indexes. That was a mouthful. Okay. Let's start with the basic concept of a table. Remember, we're not building a database here in the traditional sense. Instead, in DynamoDB, we call that set of information "tables." A table is a collection of items, and each item is a collection of attributes. I'll tell you what. Let's draw this out, so that it's easier to understand as I explain the remaining things that make up a table. First is the partition key, which is a simple primary key, composed of one attribute. In the case of our table, we are storing music data. Our primary key should be "Artist." You see that next to the partition key is a sort key. That should be a song title. When a partition and a sort key exist in a table, it is referred to as a "composite primary key" and is composed of two attributes. The first attribute, again, is Artist. The next attribute is Song Title. Okay. So, while this table isn't super useful yet, it will become useful when we add attributes. Let's think of some attributes to add that are music related. Hmm, well chart number. Let's see, that's pretty important. Genre, year, beats per minute. For creating playlists to match your speed, that's kind of important, too. All this data seems like it would be very helpful to know. So now, let's add those attributes to the table that we've drawn previously. Wow. This table's actually starting to become useful. But now, we need to figure out how this data will be queried to derive meaningful insights. Let's talk indexes. A "secondary index" is a data structure that contains a subset of attributes from a table, along with an alternate key to support query operations. A table can have multiple secondary indexes, which give you application access to many different query patterns. First up is a local secondary index. That's an index that has the same partition key as the base table, but a different sort key. So, an example of a query that we could use on a local secondary index would be to say, let's find all of the songs, the number one songs, from a particular artist, one artist. A "local secondary index" is an index that has the same partition key as the base table, but a different sort key. A good example of a local secondary index query would be all the songs from a particular decade per artist. So if I have a favorite artist, all the songs from the 80s, all the songs from the 90s. That would be an example of a query for a local secondary index. A "global secondary index" is an index that has a partition key and a sort key that can be different from those based on the base table. So, an example of a global secondary index query could be all the number one songs from a particular artist. Or, all of the songs of a particular genre - doesn't matter what artist produced them. I want you to pause and consider for a moment how you will use DynamoDB. The secret to a successful deployment is to develop your application first and determine what your queries will look like. Then, design your tables to best serve that data. Next, let's review a bit about performance. Provision throughput is represented in units of read and write capacity. There are several options to manage this. First is the ability for you to provision throughput, again, based on read and write capacity units. There are a number of ways for you to configure this setting. Be sure to use our good friend Amazon CloudWatch to help guide you with your decision to increase or decrease. Next, you can use the on-demand mode for DynamoDB. This will help you get up and running quickly without much concern to performance configurations. And then, auto scaling. Auto scaling is a way for you to run a more forgiving type of DynamoDB environment. Auto scaling allows DynamoDB to scale based on demand, much like you could with EC2 for compute. As far as performance goes, these tools are largely automated, since it's a managed service, which is really nice for you. In our next video, I will show you how to create a DynamoDB table and enter items into it to make it more useful. Thanks for watching.