Simple Hash Keys seem to be too simple to write an article, while many write about Composite Hash/Range Keys, because Composite Hash/Range Keys are useful for many complex situations. But I believe that in common applications, many of tables should be designed with Simple Hash Keys. In what situation do you use Simple Hash Keys?
For example, when you design hierarchical models like following, how do you design primary keys for each table? (All tables other than Tenant have tenant_id as a field.)
- Tenant
- User
- Team
- Project
- Task
- Team Member
Idea.1
Only "Team Member" is designed by Composite Hash/Range Key. Others are designed by Simple Hash Key.
Idea. 2
- Tenant is designed by Simple Hash Key.
- User, Team and Project's primary key would be composite (tenant_id, sub_id).
- Task's primary key would be composite ({tenant_id}_{project_range_key}, sub_id).
- Team Member's primary key would be composite ({tenant_id}_{team_range_key}, {tenant_id}_{user_range_key}).
where sub_id can be a sequential number, created_at, or else.
Update
After I posted this question, I learned more about DynamoDB and its history, and I recognize my concern much clearly now.
Before GSI was released by Amazon, we had to design tables like "Idea 2" in order to query against "tenant_id". But now we can use GSI, so we can design tables (e.g. Team, Project or Task) using the combination of "Simple Hash Key and GSI". Is that right??