开发者

Is it advisable to store some information (meta-data) about a content in the id (or key) of that content?

开发者 https://www.devze.com 2023-02-07 17:16 出处:网络
It is advisable to store some information(meta-data) about a content in the Id(or key) of that content?

It is advisable to store some information(meta-data) about a content in the Id(or key) of that content ?

In other words, I am using a time based UUIDs as the Ids (or key) for some content stored in the database. My application first accesses the list of all such Ids(or keys) of the content (from the database)开发者_开发技巧 and then accessed the corresponding content(from the database). These Ids are actually UUIDs(time based). My idea is to store some extra information about the content, in the Ids itself, so that the my software can access this meta-content without accessing the entire content from the database again.

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

  1. whether I should do so ? I am concerned since lots of processing may be required (at the time of presentation of data to user) in order to retrieve the meta data from the ids of the content!! Thus it may be instead better to retrieve it from database then getting it through processing of the Id of that content.

  2. If suggested then , How should I implement that in an efficient manner ? I was thinking of following way :-

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

where, 'timebasedUUID' is the generated ID based on the timestamp when that content was added by a user & 'userId' represents the Id of the user who put that content.

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

How should I extract this userId from the above id of the content, in most efficient manner?

Is there a better approach to store meta information in the Ids ?


I hate to say it since you seem to have put a lot of thought into this but I would say this is not advisable. Storing data like this sounds like a good idea at first but ends up causing problems because you will have many unexpected issues reading and saving the data. It's best to keep separate data as separate variables and columns.

If you are really interested in accessing meta-content with out main content I would make two column families. One family has the meta-content and the other the larger main content and both share the same ID key. I don't know much about Cassandra but this seems to be the recommended way to do this sort of thing.

I should note that I don't think that all this will be necessary. Unless the users are storing very large amounts of information their size should be trivial and your retrievals of them should remain quick


I agree with AmaDaden. Mixing IDs and data is the first step on a path that leads to a world of suffering. In particular, you will eventually find a situation where the business logic requires the data part to change and the database logic requires the ID not to change. Off the cuff, in your example, there might suddenly be a requirement for a user to be able to merge two accounts to a single user id. If user id is just data, this should be a trivial update. If it's part of the ID, you need to find and update all references to that id.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号