Designing tables in Amazon dynamodb

I am new to DynamoDB and I have a big mess: what my tables look like.

I read the posts here: (recommended for those who haven't read it yet) http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/BestPractices.html

And now I have some dilemmas that I think everyone who starts using DynamoDB will have.

Firstly, my tables: STUDENTS, TEAMS, PROJECTS

STUDENTS : id , age ...

BODIES : id , student-1-id, student-2-id, current-project, prev-project, last-updated-on

PROJECTS : id , team identifier, list of questions, list of students, list of student2answers

some comments:

  • As you can see, I do not use the range key. I need? .
  • each answer is json (question number, text, insert date)
  • Each student can be in several teams.

My dilemmas:

  • I want all the teams of a particular student to be updated after a certain date.

Currently, I use 2 scan operations: one search for student1 and a second search for student2.

**Is there a better way ?** 

I thought about adding a new table: user-Battles: student-id, team-id so I can request commands for specific students and then batch_get_item all the teams, but what about the latest update? how can i also request this inside batch_get_item?

  1. When a project fails, I don’t use it anymore. what to do with old items? Delete? Move them to another table?

  2. In the project table, the attributes that can be updated are response attributes so I think to move them to another table for presentations.

Do I need to move them if I update them twice? (when student1 sends an answer, and when student2 sends an answer - then the project is old)

* If I create a new table for answers, I will not need to store them in JSON format

How do you design tables? Please let me know.

+8
database nosql amazon-dynamodb database-design
source share
1 answer

Good question with lots of details :)

If I had only one piece of advice, this would be:

Keep in mind that with NoSQL this is not only normal, but normal, it is even recommended to de-normalize your data.

This suggests that for you the "dilemma" your offer was pretty good. You must deaminate with a date like range_key . One way could be to add a table as follows:

  • hash_key : student
  • range_key : date
  • team : team_id

But still, this is not ideal, as the table will continue to grow. Each update inserts a new object. Indeed, editing the key is not possible. You will need to do your own cleanup code.

In DynamoDB, you don’t have to worry about performance slowdown caused by "old" elements (except for scanning), this is the main strength of DynamoDB. However, it is always good practice to keep data clean, but to be consistent. If you start moving past projects, move all of them or you won’t know where your data is.

Final suggestion: are you sure ids is the best thing to describe your objects? In most cases, a name, date, or any unique attribute makes the best key.

+2
source share

All Articles