I am afraid Cassandra is not a good fit for dealing with mutable orders. (Consider Redis Sorted Sets instead)
With that said, you can actually achieve this using CAS-like semantics (compare-and-set) and light-weight transactions which will make your update around 20x slower.
You will also need an additional table that will serve as a lookup for current like_count per bucket_id/photo_id.
create table yy (
bucket_id int,
photo_id int,
like_count int,
PRIMARY KEY((bucket_id,photo_id))
)
Then do a light-weight-transactional delete from xx followed (if success) by an re-insert into xx and update to yy:
Some pseudo code:
for (;;) {
ResultSet rs1 = select like_count from yy where bucket_id = ? and photo_id = ?
int old_score = rs1.one().getInt(0)
if (new_score == old_score) break;
ResultSet r2 = delete from xx where bucket_id = ? and photo_id = ? and like_count = old_score IF EXISTS
if (rs2.one().getBool(0)) {
insert bucket_id, photo_id, photo_id, username, like_count into xx values (?, ?, ?, new_score)
update yy set like_count = new_score where bucket_id = ? and photo_id = ?
break;
}
}