What is fractional indexing and why do Kanban boards use it?
IntermediateDesign patterns and architecture interview questionBy UIRound, updated 23 November 2026
Short answer
Fractional indexing stores the order of a list as a sortable key on each item instead of an integer position. To move a card between two others, you generate a new key that sorts between their keys, such as a0V between a0 and a1, and update only the moved card. Nothing else is renumbered, so a drag is one small write and concurrent moves of different cards never conflict.
The problem with integer positions
The obvious model is a position column: 0, 1, 2, 3. Moving the card at position 7 to position 2 means shifting positions 2 to 6 up by one. That is six writes for one drag, and it gets worse:
- Big lists, big writes. Moving a card to the top of a 5,000-card column rewrites every card in it.
- Concurrency. Two people dragging different cards at the same time both rewrite overlapping ranges. Whoever saves last wins, and the column can end up with duplicate or missing positions.
- Sync traffic. Every renumbered card has to be sent to every other client watching the board.
- Offline and optimistic updates. "Move index 3 to index 7" means something different on a client whose list has changed since, so queued moves replay into the wrong place.
What you want is an order where inserting between two items touches only the inserted item.
The idea: always leave room in between
Between any two numbers there is another number. Give the cards positions 1, 2 and 3; to put a card between 1 and 2, give it 1.5. Between 1 and 1.5 is 1.25. Each item's key is independent, and the list is sorted by key.
Floats are the version you see in many APIs. Trello's REST API, for example, gives each card a numeric pos. The catch is precision: a double has 53 bits of significand, so if users keep dropping cards into the same gap, halving it each time, you run out of distinct values after roughly 50 inserts and two cards get the same position.
Fractional indexing fixes that by using strings as arbitrary-precision fractions. A string can always get one character longer, so there is always a key in between. David Greenspan's write-up, "Implementing Fractional Indexing", is the reference most libraries follow, and Figma described the same technique for ordering layers in its multiplayer editor. Jira's LexoRank is a close relative.
How the keys work
The common scheme uses base-62 digits, 0-9A-Za-z, which happen to be in ASCII order, so plain string comparison sorts them correctly. A key like a0V reads as:
a: a header saying the integer part has one digit.0: the integer part.V: the fractional part.Vis digit 31 of 62, so it is about halfway.
The fractional-indexing package on npm implements this:
import { generateKeyBetween, generateNKeysBetween } from "fractional-indexing";
const first = generateKeyBetween(null, null); // "a0"
const second = generateKeyBetween(first, null); // "a1" append at the end
const zeroth = generateKeyBetween(null, first); // "Zz" prepend at the start
const middle = generateKeyBetween(first, second); // "a0V" between a0 and a1
generateNKeysBetween("a0", "a1", 3); // ["a0G", "a0V", "a0l"]Appending and prepending only change the integer part, so lists that mostly grow at one end keep short keys. Inserting in the middle uses the fractional part. The heart of it is a midpoint between two digit strings:
const DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
// `a` is the lower fraction ("" means 0), `b` the upper one (null means 1).
function midpoint(a, b) {
if (b !== null) {
let n = 0;
while ((a[n] ?? "0") === b[n]) n++; // keep the shared prefix
if (n > 0) return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
}
const lo = a ? DIGITS.indexOf(a[0]) : 0;
const hi = b !== null ? DIGITS.indexOf(b[0]) : DIGITS.length;
if (hi - lo > 1) return DIGITS[Math.round((lo + hi) / 2)]; // a digit fits between
if (b !== null && b.length > 1) return b[0]; // b's first digit alone sorts below b
return DIGITS[lo] + midpoint(a.slice(1), null); // go one digit deeper
}
midpoint("", null); // "V"
midpoint("V", "W"); // "VV"Using it in a Kanban board
The data model becomes a rank string per card plus its column:
type Card = { id: string; columnId: string; rank: string; title: string };
const byRank = (a: Card, b: Card) =>
a.rank < b.rank ? -1 : a.rank > b.rank ? 1 : a.id < b.id ? -1 : 1; // id breaks tiesOn drop, the client looks up the cards immediately above and below the drop target, computes a key between them, updates the card optimistically and sends the move. Two details matter:
- Compare by code unit, not locale. Use
<or a byte-order collation in the database (COLLATE "C"in PostgreSQL).localeCompareand many default collations treataandAas neighbours and will sort the keys wrongly. - Send intent, not just the key. Sending
{ cardId, columnId, afterId, beforeId }lets the server compute or check the key against its current state. If the neighbours have moved by the time the request arrives, the server can still place the card next toafterIdinstead of trusting a key computed from stale data.
Practise the client side in a drag-and-drop Kanban board and a Trello-like app with undo and persistence.
Concurrent inserts and jitter
The basic algorithm is deterministic. If two users drop a card between a0 and a1 at the same moment, both get a0V. The two cards now have equal keys, and there is no key strictly between them, so the next insert at that spot fails or lands on the wrong side.
Three common fixes, often combined:
- Tie-break by id when sorting, so equal keys still give every client the same order.
- Add jitter: append a few random digits to each generated key. Two clients picking the same gap then get different keys almost every time, at the cost of slightly longer keys.
- Let the server assign the key from the neighbour intent, serialised per column, so it never hands out duplicates. The client's optimistic key is replaced by the server's when the response arrives.
A related quirk: if two users each insert several cards into the same gap, their cards can interleave. For a board this is rarely a problem. For text, where interleaved characters are garbage, you need a sequence CRDT instead, which is one reason collaborative editors use OT or CRDTs rather than rank keys.
Key growth and rebalancing
Every middle insert can add a character. Each base-62 digit holds a little under 6 bits, so dropping cards repeatedly into the same shrinking gap grows the key by about one character every six moves. Real usage spreads inserts around and keys stay short, but a column that people keep reordering at the top can build up long keys over months.
The fix is a background rebalance: rewrite the keys of a whole column evenly (for example with generateNKeysBetween(null, null, count)), as a single operation that is broadcast to clients like any other change. LexoRank-style systems add a bucket prefix so a rebalance can write into a fresh key space while old keys still sort. Because pending client moves are stored as neighbour intents rather than raw keys, they still apply correctly after a rebalance. The Jira-style issue board design covers this at scale.
Follow-up questions interviewers ask
Why not just use floats?
Floats work for small lists and many apps ship with them. They run out of precision after about 50 inserts into the same gap, and the failure is silent: two cards get the same value. Strings never run out, they compare exactly, and they serialise the same way in every language.
What happens when two users move the same card?
The moves conflict on one row, and the server applies them in order, usually last write wins. Each client receives the final key and re-sorts. That is acceptable for a card. Moves of different cards never conflict, which is the main win over integer positions.
How does undo work with rank keys?
Store the previous neighbours, not the previous key. Undo sends a new move between those neighbours, because the old key may now collide with something else or have been rewritten by a rebalance.
Does fractional indexing work for nested lists or trees?
Yes. Give each node a parentId and a rank among its siblings. Moving a node changes its parent and its rank, still one row. The collaborative playlist design applies the same idea to a shared list edited by many people.
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Design a Jira-style issue board for 10,000 issues: virtualised columns, rank keys, live updates and conflictsHard55 min
- Design a collaborative music playlist: concurrent add, remove and reorder with real-time updatesHard50 min
- Build a drag-and-drop Kanban boardMedium45 min
- Build a Trello-like Kanban app supporting nested cards, drag-and-drop, undo/redo, and persistenceHard90 minFree
- Design a Trello board: lists and cards with drag and drop, a card details modal, live teammate updates and offline editsHard55 min