mardi 24 février 2015

In what situation do you use Simple Hash Keys on DynamoDB?

Because Composite Hash/Range Keys are useful for many complex situations, many of articles write about Composite Hash/Range Key. Simple Hash Keys seems to be too simple to write an article for DynamoDB specialists. But I believe that in common applications, many of tables should be designed with Single Hash Keys. How many percentages of tables do you use Simple Hash Keys as a primary key? And, in what situation do you use Simple Hash Keys?


For example, when you design following tables for multi-tenant application, 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.


I prefer an "Idea 1", but others says "Idea 2" is better because many samples in articles uses Composite Hash/Range key for hierarchical objects.


How do you think about it?





Aucun commentaire:

Enregistrer un commentaire