开发者

Designing Unique Keys(Primary Keys) for a heavily denormalized NoSQL database

开发者 https://www.devze.com 2023-02-07 21:50 出处:网络
I am working on a web application related to Discussion forums using Java and Cassandra database. I need to construct \'keys\' for the rowsstoring the user\'s details and & another set of rows st

I am working on a web application related to Discussion forums using Java and Cassandra database.

I need to construct 'keys' for the rows storing the user's details and & another set of rows storing the content posted by the user.

One option is to get the randomly generated UUID provided by Java language开发者_运维问答, but these are 16 bytes long. and since NoSQL database involves heavy denormalization, I am concerned whether I would be wasting lots of disk space, RAM and other resources if the key could be generated in smaller sizes.

I need to generate two types of keys, one for the Users & other for Content Posted by Users.

For the Content posted by users, would timestamp+userId be a good key. where timestamp is the server time at which content was posted and userId refers to key of user row.

Any suggestions, comments appreciated ..

Thanks Marcos


Is this a distributed application?

Then you could use a simple synchronized counter and initialize it on startup with the next available id.

On the other hand a database should be able to handle the UUID hashes as created by java. This is a standard for creating things like sessionIds, that need to be unique. Your problem is somewhat similar since a session in your context would represent a set of user input.

0

精彩评论

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

关注公众号