Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I can't speak for Cassandra or Hbase, but let me address the Riak part.</p> <p>Yes, Riak would be appropriate for your scenario (and I've seen several companies and social networks use it for a similar purpose).</p> <p>To implement this, you would need the plain Riak Key/Value operations, plus some sort of indexing engine. Your options are (in rough order of preference):</p> <ol> <li><p><strong>CRDT Sets</strong>. If your 1-N collection size is reasonably sized (let's say, there's less than 50 messages per user or whatever), you can store the keys of the child collection in a <a href="http://docs.basho.com/riak/latest/dev/using/data-types/" rel="nofollow">CRDT Set Data Type</a>.</p></li> <li><p><strong>Riak Search</strong>. If your collection size is large, and especially if you need to search your objects on arbitrary fields, you can use <a href="http://docs.basho.com/riak/latest/dev/using/search/" rel="nofollow">Riak Search</a>. It spins up Apache Solr in the background, and indexes your objects according to a schema you define. It has pretty awesome searching, aggregation and statistics, geospatial capabilities, etc.</p></li> <li><p><strong>Secondary Indexes</strong>. You can run Riak on top of an <a href="http://docs.basho.com/riak/latest/ops/advanced/backends/leveldb/" rel="nofollow" title="LevelDB storage back end">eLevelDB storage back end</a>, and enable <a href="http://docs.basho.com/riak/latest/tutorials/querying/Secondary-Indexes/" rel="nofollow" title="Secondary Indexes">Secondary Index</a> (2i) functionality.</p></li> </ol> <p>Run a few performance tests, to pick the fastest approach.</p> <p>As far as schema, I would recommend using two buckets (for the setup you describe): a User bucket, and a Message bucket.</p> <p>Index the message bucket. (Either by associating a Search index with it, or by storing a user_key via 2i). This lets you do all of the required operations (and the message log does not have to fit into memory):</p> <ul> <li><strong>Store from 1 to X messages per registered user</strong> - Once you create a User object and get a user key, storing an arbitrary amount of messages per user is easy, they would be straight up writes to the Message bucket, each message storing the appropriate user_key as a secondary index.</li> <li><strong>Get the number of stored messages per user</strong> - No problem. Get the list of message keys belonging to a user (via a search query, by retrieving the Set object where you're keeping the keys, or via a 2i query on user_key). This lets you get the count on the client side.</li> <li><strong>retrieve all messages from a user at once</strong> - See previous item. Get the list of keys of all messages belonging to the user (via Search, Sets or 2i), and then fetch the actual messages for those keys by multi-fetching the values for each key (all the official Riak clients have a <code>multiFetch</code> capability, client-side). </li> <li><strong>delete all messages from a user at once</strong> - Very similar. Get list of message keys for the user, issue Deletes to them on the client side. </li> <li><strong>delete all messages that are older than X months</strong> - You can add an index on Date. Then, retrieve all message keys older than X months (via Search or 2i), and issue client-side Deletes for them.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload