DynamoDB in examples, Example 2.2: Table secondary indexes

DynamoDB table may have two kinds of secondary indexes:

local

global

Possible to define up to 5 local and 5 global secondary indexes (see DynamoDB limits).

Local secondary index has a big disadvantage: For every distinct hash key value, the total sizes of all table and index items cannot exceed 10 GB. So, if You don't sure what type of secondary index to choose - choose global secondary index.

Think about secondary index like one another table with different key schema but the same data.
When we create a new item, we need to create it in table and in every secondary index. So, summary consumed write cpacity will increase.
Write throughput for every global secondary index has to be equal to table write throughput.

This is one bad thing about indexes: they increase write throughput we pay for.
Another bad thing: we can't add or remove secondary indexes after table was created.
So, design table structure carefully.

If it happens that we will realize that we really need more secondary indexes but the table already contains data:

create new table

migrate all data from old one

Back to unique page views example. New requirements:

list of pages particular user viewed

list of users who viewed particular page

We need two global indexes: by user and by page. As range, I'll use created time.