This particular model is somewhat complex for a number of reasons.
For example, with a box identifier as a string, a query for a range of cells will require a range query in Cassandra (as opposed to slice a column), which means using an ordered delimiter. An ordered delimiter is almost always a bad idea.
Another problem is the need to increase the size of the element, since this requires the use of a counter column family. Bar columns only store counter values.
Having noted the need for several box identifiers for a moment, you can simulate this using several tables in CQL3 as follows:
CREATE TABLE boxes ( id int PRIMARY KEY, belongs_to_user text, box_title text, ); CREATE INDEX useridx on boxes (belongs_to_user); CREATE TABLE box_items ( id int, item int, size counter, PRIMARY KEY(id, item) ); CREATE TABLE box_item_names ( id int PRIMARY KEY, item int, name text ); BEGIN BATCH INSERT INTO boxes (id, belongs_to_user, box_title) VALUES (23442, 'user1', 'the box title'); INSERT INTO box_items (id, item, name) VALUES (23442, 1, 'itemname1'); INSERT INTO box_items (id, item, name) VALUES (23442, 1, 'itemname2'); UPDATE box_items SET size = size + 44 WHERE id = 23442 AND item = 1; UPDATE box_items SET size = size + 24 WHERE id = 23442 AND item = 2; APPLY BATCH
It is important to note that the BATCH mutation above is both atomic and isolated.
From a technical point of view, you can also denormalize it all into one table. For instance:
CREATE TABLE boxes ( id int, belongs_to_user text, box_title text, item int, name text, size counter, PRIMARY KEY(id, item, belongs_to_user, box_title, name) ); UPDATE boxes set size = item_size + 44 WHERE id = 23442 AND belongs_to_user = 'user1' AND box_title = 'the box title' AND name = 'itemname1' AND item = 1; SELECT item, name, size FROM boxes WHERE id = 23442;
However, this does not give any guarantees of correctness. For example, this model allows items in the same box to have different users or names. And since the boxes family does this with the column counter family, it limits how you can change the layout in the future.