0

I am building an application in Java. My database (Cassandra) understands only byte[] as data. Thus I am free to choose among the several datatypes, for various entities IDs like the userIds or contentIds.

What should be the preferred datatype for allocating these IDs. I am looking towards sequential integeral values as userIds for the users on the application. By the database design (as planned out), a single user is going to have 4 rows in the DB. To distinguish between these four rows, I could perhaps add an extra digit to userId towards the right most digit, that will help me in distinguishing among the 4 rows.

Does this look like a good solution? Or would String Ids be preferred ?

Any feedback is appreciated..

3 Answers 3

4

Definately integer ids. I've seen cases where some databases performs full-table scans with string ids. There might also be reststrictions on the length of the id field (e.g., using an encoded url for id is a bad idea). Besides id generation is best left to the database, and integers seems like the natrual choise.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Johan. Would you also like to add upon the possible solutions in order to distinguish the four types of rows. If there had been strings as Ids, I would have probably concatenated some postfix to those userIds ... does the solution, that I proposed with my question, seem like a good way to you for this purpose?
You could, as long as you let this implementation detail be hidden in your DAO.
1

Integer ids in general but...

Why does a user have 4 rows in a single table?

1 Comment

splitting the rows by various kinds of data(for a row oriented datastore)...so that each time you need some specific data for the user, just that specific row is fetched from the database. This helps in row cache too(provided by Cassandra DB), you can just warm those rows which are required (all data of user may not be required at once).
1

In my opinion everything depends on how much entities you will need to store in db. Integer type has limited set of values and if you know that you wont exceed that limit use Integer otherwise consider using Long or String type.

1 Comment

In Java, integer values range from around (-)2000 million to (+)2000 million, I dont think that it would be a limitation for me in terms of userIds ofcourse. but for the ids of the content of users it may be worthwhile to go with Long type..perhaps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.