Is breaking the atomicity rule justified here?

working one a side project and i came across a problem , i want users to save to their profile their preferred colors, user can have one or multiple preffered colors , the good way to do it is to just have a separate table UserPreferredColors
but im thinking, since its use case will be very limited why waste a whole table for that, maybe just add it to the user table as column where the value is a list, the colors will not be detailed, there isnt specific hex or names just a standardised list of colors the user can select one or multiple like this screenshot i took from Color Hunt
No description
19 Replies
ἔρως
ἔρως2w ago
why the colors exist in the first place?
mino
minoOP2w ago
so to add more context, on the utility of this either column or seperate table, so in the feed system, posts will have properties like describtion and all the standard solcial media posts, but it will also have dominating colors, and based on the user color preference we will push certain posts higher, so the backend is very affected by this decision since it is responsable for filling the user feed
ἔρως
ἔρως2w ago
sounds like a tag system, not gonna lie
mino
minoOP2w ago
yea it is
ἔρως
ἔρως2w ago
why not just have a table with colors for the tags or something?
mino
minoOP2w ago
i dont understand, where is the link to the user or the post
ἔρως
ἔρως2w ago
nowhere it's a tag system you have tags, and each post has multiple tags and each tag has a color
mino
minoOP2w ago
i still dont get it, is a tag system a design patern i dont know about
ἔρως
ἔρως2w ago
it's just tags just like in a blog post
mino
minoOP2w ago
yea but how does it link back to the user prefering certain tags
ἔρως
ἔρως2w ago
a user tag preference table or a json array
mino
minoOP2w ago
yea i know that much but which one to use
ἔρως
ἔρως2w ago
users don't update tags that often, so, an array may be enough
mino
minoOP2w ago
i see, thank a lot, also generalising it to a tags table makes a lot more sense than what i had before so thanks for that too
ἔρως
ἔρως2w ago
you're welcome
ErickO
ErickO2w ago
Nobody seems to have mentioned it so I will, this is NOT an atomicity problem, this is normalization problem, very different things. This tag system is generally what we call a many-to-many relationship with a JUNCTION TABLE, basically you have one table for idk, user posts or whatever, a table for tags AND the junction table that connects them both; This is completely normalized and avoids duplicated data HOWEVER, it can be costly if you're constantly accessing this data but for small apps is aight
mino
minoOP2w ago
so i learned this stuff a while ago and in french so forgive me if something was lost in the translation, but i know there is atomicity in database transactions, but also in normalisation the Atomic values (from first normal form) about whether a column contains a single indivisible value
ErickO
ErickO2w ago
ah that's a different concept and never heard it called "atomicity" before, just call it normalisation cause atomicity is database transaction stuff regardless, same answer, just use a junction table that said, don't think everything has to be normalized in your db, using JSON isn't uncommon now that dbs have gotten a lot better at manipulating it
mino
minoOP2w ago
got it, thank you so much

Did you find this page helpful?