Random curious question. I was pondering the kanban backend. How do you store the order of the kanban cards in your database and keep that in sync with what's in the UI?
Here is the answer for Trello: each card and list has a field called “pos” which is a number. The initial values are spread out (e.g. 1000, 2000, 3000) and then when you move a card, it takes on the average of the two adjacent cards.
So, if I move the 3rd card to the 2nd position, its “pos” becomes 1500. This means it doesn’t have to constantly renumber the cards -- but, every once and a while, the server does reorder the “pos” fields for a whole list and send the new values down the socket.
I was going to guess linked lists/graphs as that is my goto for extremely flexible local structure. But the sparse array is probably better, relational databases hate linked lists.
Thank you for this, that's so simple and I'd never stumble on that solution which is embarrassing haha. How do you know the Trello internals by the way? You work there?
Well, not quite. Although lexorank is similar, the mothod described above is not lexorank. Lexorank uses strings and buckets and a completely different set of math to work it out.
Order is stored to sort field as number. When changing order with JQuery Draggable/Droppable/Sortable, it saves new order to browserside MiniMongo, that is made with Javascript, and then to serverside MongoDB. It is possible use mouse or touchscreen to drag drop reorder board icons at All Boards page, swimlanes, lists, cards and checklists. There are also roles at right sidebar avatar icons popup settings, so BoardAdmin can drag drop everything, and there are some limits for other roles, like Normal, CommentOnly etc https://news.ycombinator.com/item?id=44165257
For realtime updates, Meteor web framework reads realtime changes from MongoDB OpLog (operations log), and with Publish/Subscribe at realtime updates all changes immediately for all users, like what card moved, etc.
There is in progress of adding support for other databases, like SQLite etc.