Patterns for Distributed Hash TablesItem Groups

time to read 3 min | 427 words

And yet another post in my series on using Distributed Hash Tables (DHT).

The previous ones are:

    Right now I want to talk about item groups, or namespaces. In DHT, a namespace isn't quite the same as the one we are familiar with from programming language. It is a way to refer to a group of items in a one sweep. Usually, this is used either to retire a whole bunch of items at the same time, or redirect them (which might be the same thing). This is usually useful in caching scenarios much more than in DHT scenarios, but it is an important building block.

    Let us consider the idea of having a shop, with all its products in the DHT. We have some batch process that updates a lot of the product information, so we want to be able to retire all the products in the cache in one go. Having to go through the entire products list would be expensive (N remote calls) and will produce invalid view of the data, since some of the items will be retired while some still in the cache, etc.

    One way of dealing with that is by defining an item group. An item group is defined so:

    • {group name}_product_1
    • {group name}_product_2
    • {group name}_product_3

    The {group name} is not the actual value there, of course. Instead, {group name} refers to a key in the DHT as well. That key contains a value (usually numeric one) that we use when we query the data. So, getting product #1 from the DHT will involve:

    • GET "{group name}" - return 432
    • GET "432_product_1"

    Using this approach, we can change, in one sweep, all the items that belong to this group. Again, this is nothing but convention, but it is a very useful one. In fact, we will see in a the next post that it can be used to do some pretty interesting things.

    More posts in "Patterns for Distributed Hash Tables" series:

    1. (09 Aug 2008) Range Queries
    2. (09 Aug 2008) Lookup by property
    3. (09 Aug 2008) Cheap Cross Item Transactions
    4. (09 Aug 2008) Item Groups
    5. (08 Aug 2008) Locality