9.1: Separate application attributes from your indexing attributes
In Chapter 3, we first discussed the concept of overloading the primary key and secondary indexes in your DynamoDB table. To overload your primary key, you use generic names like PK and SK for your primary key attributes. The values for these generic attributes are specifically designed to create the proper item collections and ordering to handle your queries.
If you click the "Get All Customers" button, you'll see the stringified data from your DynamoDb table. Notice that each object has multiple properties including "pk" and "sk".
You can add new customers here
[]
"pk" and "sk" are related to the DynamoDb data model but have no meaning in the application business logic. These as 'indexing attributes', as they’re only there for indexing your data in DynamoDB.
I advise you to keep a separation between these two kinds of attributes. Your application attributes will often inform parts of your indexing attributes. Here, the phone attribute is used to fill in sk template.
Don’t remove the phone attribute from your item since it’s already encoded into your SK. It adds complexity and risks data loss if you change your data model and indexing attributes in the future. It will result in slightly larger item sizes due to duplicated data, but I think it’s worth it.