News for hackers. Stuff that matters.
Re:The surprisingly difficult problem of user-defined order ... by asddubs on Friday January 15, 2021 @09:05PM (#25799234)
IMO the first approach is the best, unless there's a very high number of items (which usually in these scenarios, there's not, even a couple thousand wouldn't be catastrophically bad to update if it's not a common operation). they all kind of suck but everything else seems worse.
Re:The surprisingly difficult problem of user-defined order ... by spiffytech on Friday January 15, 2021 @10:02PM (#25799609)
A basic ordered list of integers can cause a lot more problems than I would have expected at first glance.

Updating dozens/hundreds/thousands of records at once is obviously unnecessarily heavy to process. But depending on your storage layer's locking model, it could cause high lock contention if concurrent actors are updating the same list and fight over large fractions of the dataset with every update.

If you're working in a networked scenario, naïve implementations can turn into transmitting a lot of data across the wire for every single reposition.

It's also algorithmically challenging in concurrent scenarios. If I update my local state rearrange items, and you update your local state to rearrange items in an overlapping range, when they have to sync up this quickly turns into the developer having to learn to implement CRDTs or Operational Transforms. You could implement optimistic or pessimistic locking, but you have to lock such a large fraction of the dataset that it's easy to limit throughput.

Distributed/eventual-consistency problems are particularly challenging with ordering solutions of this variety, but the difference between one operation updating a wide swath of values vs just the single updated value can make a difference in how primitive a reconciliation algorithm the develop can bring to bear.

Re:The surprisingly difficult problem of user-defined order ... by asddubs on Saturday January 16, 2021 @02:12AM (#25800689)
that's true, I forgot that when I last faced this problem it was specifically a situation where there would not be concurrent updates