tags:

views:

403

answers:

2

Hello,

I am trying to understand, how can Voldermort be used? Say, I have this scenario:

Since, Voldemort is a key-value pair. I need to fetch a value (say some text) on the basis of 3 parameters.

So, what will be the key in this case? I cannot use 3 keys for 1 value right, but that value should be search able on the basis of those 3 parameters.

Am I making sense?

Thanks

EDIT1

eg: A blog system. A user posts a blog: User's data stored: Name, Age and Sex The blog content (text) is stored.

Now, I need to use Voldemort here, if a user searches from the front end for all the blog posts by Sex: Male

Then, my code should query voldemort and return all the "blog content (text)" which have Sex as Male.

So, as per my understanding:

Key = Name, Age and Sex
Value = Text

I am using Java.

+1  A: 

Edited answer to fit with example added to question:

The thing to understand about Voldemort is that it's a very simple key-value store. As far as I know about it, the only thing you can do is store a value under a key, and then fetch those values by key. So for your example case, if you really want to use Voldemort, you have a few options.

So, for example, you've said that you're storing data for users. So, you might have something like this:

Key = user-Chad
Value = Name:Chad Birch, Age:26, Sex:Male

Now, if I want to post a new blog post, you also need to store that under a key. So you could do something like this:

Key = blog-Chad1
Value = Here is my very first blog post.

Now, your problem is that you need some way to look up all the blog posts made by users with Sex:Male, but there's no way to get that data directly. At this point, you have to either:

  1. Pull out every single user, check if they're male, and if they are, pull out their blog posts.
  2. Start storing more stuff in other key-value pairs so that you can look this up.

To implement #2, you could add another pair like this:

Key = search-Sex:Male
Value = Chad1 Chad2 Steve1 ...

Then, when someone does a search for Sex:Male, you pull out the value for this, split it up, and then go fetch all those blog posts.

Does that make sense? Using a k-v store is quite a bit different from a database, because you lose all these relational abilities.

Chad Birch
The answer you suggested is a workaround or a correct way to use Voldemort (key-value pair)
zengr
That was an awesome solution, so tell me, if I use your suggested method, I am actually twisting the actual purpose of Voldemort and unnecessarily using it or that is correct?
zengr
Well, you can't really "twist the purpose" of it. All Voldemort does is take values and store them under keys. It doesn't care what they are. What you have to figure out is where to strike a balance between storing more k-v pairs to make lookups faster (which makes you have to do a bunch of changes whenever someone posts something) or storing less but needing to do repeated lookups to get the information you want.
Chad Birch
For example, in the examples I gave, every time a male user makes a new blog post, you're going to have to pull out the `search-Sex:Male` key and change its value to include the new post. However, if you just stored a list of male users, you wouldn't have to do this. But then when someone searches for posts by males, you have to do additional lookups. First you'd have to get the list of all male users, then you have to get lists of all their posts, instead of just going directly to the result.
Chad Birch
+1 to you! Thanks for the answer!
zengr
+1  A: 

I don't think you can do that directly with a key-value store, but one way to work around is to store the user in multiple places.

For example, you have key-value mapping of a user to a list of blog posts. You also have a mapping of an age to a list of users. Also a gender to a list of users. Now if you want to search by age or gender you pull the corresponding list of users, and then pull all of their blog posts.

Part of the reason a key-value store like Voldemort can work is that storage and queries are cheap enough that you can do extra ones.

The problem, though, with the above scheme is that if you're using Voldemort in a distributed way you're better off with lots of keys that map to short lists of data (so you can distribute based on key) which something like mapping gender to user would violate (only a few keys with potentially very large lists of data for each).

JacobM