Is it desirable to store some information (metadata) about the content in the id (or key) of this content?

Is it desirable to store some information (metadata) about the content in the Id (or key) of this content?

In other words, I use time-based UUIDs as identifiers (or keys) for some content stored in the database. My application first accesses the list of all such identifiers (or keys) of the content (from the database), and then refers to the corresponding content (from the database). These identifiers are actually UUIDs (time). My idea is to store additional information about the contents in the identifiers themselves so that my software can access this meta-content without having to access all the contents from the database again.

My application context is a website using Java technology and a Cassandra database. So my question is:

  • should i do this? I am worried that it may take a lot of processing (while presenting data to the user) to get metadata from the content identifiers! Thus, instead it is better to get it from the database, and then get through the processing of the identifier of this content.

  • If offered, how should I implement this effectively? I thought of the following: -

Id of a content = 'Timebased UUID' + 'UserId'

where 'timebasedUUID' is the generated identifier based on the timestamp when this content was added by the user, and 'userId' represents the identifier of the user who posted this content.

so my example Id would look something like this: - e4c0b9c0-a633-15a0-ac78-001b38952a49 (TimeUUID) -- ff7405dacd2b (UserId)

How can I extract this userId from the above content identifier in the most efficient way?

Is there a better way to store meta information in identifiers?

+4
source share
2 answers

I hate talking about it, since you seem to have thought a lot about it, but I would say that it is not practical. Storing such data at first sounds like a good idea, but ultimately causes problems because you will have many unexpected problems reading and saving data. It is best to store individual data as separate variables and columns.

If you are really interested in accessing meta-content with the main content, I would make two families of columns. One family has meta content, and the other has larger main content, and both have the same ID key. I don't know much about Cassander, but this seems to be the recommended way to do such things.

I should note that I do not think that all this will be necessary. If users do not store very large amounts of information, their size should be trivial, and their extraction from them should remain fast.

+4
source

I agree with AmaDaden. Mixing identifiers and data is the first step on the road that leads to a world of misery. In particular, you will eventually find a situation where business logic requires a change in a piece of data, and database logic requires that the identifier does not change. In your case with the cuff, it may be necessary for the user to combine the two accounts into one user ID. If the user ID is just data, this should be a trivial update. If this is part of the identifier, you need to find and update all links to this identifier.

+1
source

Source: https://habr.com/ru/post/1337935/


All Articles