Getting random objects filtered by a set of criteria

David Smith dizzyd at
Sun Jan 10 08:58:13 EST 2010

On Sat, Jan 9, 2010 at 9:01 AM, Dmitrii Dimandt <dmitriid at> wrote:

> I want to show the user a photo to vote for. This has to be a random photo
> from those he hasn't voted for yet.
> In a prior conversation Kevin Smith suggested[1] I use M/R for such a task.
> Well, not only do I have to understand how to write such a M/R :) I also
> need to know whether  it's ok to run such a query on every page request.

I wouldn't recommend using M/R for this task, simply because of the
frequency you want to perform this operation. A better solution, IMO, would
be to use your keyspace to your advantage. Store the pictures keyed by an
integer; in this way you can randomly select an integer between 0..MaxKey
and return that with a single GET operation. Of course, if you have an
existing key storage system that is based on some other key, this may mean
you wind up storing some data twice (i.e. denormalized), but that's a
reasonable trade-off for efficiency/latency.

Just my $0.02. :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the riak-users mailing list