Hello stackoverflow community,
This question is about modeling one-to-one relationships with multiple entities involved.
Say we have an application about students. Each Student
has:
Profile
(name, birth date...)Grades
(math score, geography...)Address
(city, street...).
Requirements:
- The
Profile
,Grades
and theAddress
only belong to oneStudent
each time (i.e. one-to-one). - A
Student
has to have allProfile
,Grades
andAddress
data present (there is no student without grades for example). - Updates can happen to all fields, but the profile data mostly remain untouched.
- We access the data based on a
Student
and not by querying for the address or something else (a query could be "give me the grades of student John", or "give me profile and address of student John", etc). - All fields put together are bellow the 400kb threshold of DynamoDB.
The question is how would you design it? Put all data as a single row/item or split it to Profile
, Grades
and Address
items?
My solution is to go with keeping all data in one row defined by the studentId as the PK and the rest of the data follow in a big set of columns. So one item looks like
[studentId, name, birthDate, mathsGrade, geographyGrade, ..., city, street]
.I find that like this I can have transnational inserts/updates (with the downside that I always have to work with the full item of course) and while querying I can ask for the subset of data needed each time. On top of the above, this solution fits with two of the most important AWS guidelines about dynamo:
The reason for my question is that I could only find one topic in stackoverflow about one-to-one modeling in DynamoDB and the suggested solution (also heavily up-voted) was in favor of keeping the data in separate tables, something that reminds me a relational-DB kind of design (see the solution here).
I understand that in that context the author tried to keep a more generic use case and probably support more complex queries, but it feels like the option of putting everything together was fully devalued.
For that reason I'd like to open that discussion here and listen to other opinions.