Scrivio Interview library
ConceptPrincipal6 min read · updated 12 November 2026

The JDK provides a concurrent sorted map built on a skip list (ConcurrentSkipListMap) rather than a concurrent balanced tree. Why, and what general lesson does it give about choosing data structures and system designs under concurrency?

A balanced tree keeps its shape by rotating nodes, and a single insert can trigger rotations and recolouring along the path up to the root, so concurrent updates touch shared nodes near the top and contend with each other; making that lock-free is extremely hard. A skip list keeps balance by random choice instead, so each update changes only a few neighbouring links, which can be done with compare-and-set. The price is more memory per entry and less predictable per-operation cost. The general lesson is to prefer structures and system designs where updates touch little shared state, which is the same reason partitioning and local updates scale better than global coordination.

Why this question is asked

Most engineers use ConcurrentSkipListMap without asking why the JDK has no concurrent TreeMap. The answer is a small, concrete lesson about concurrency that applies far beyond collections: what limits scaling is not the cost of an operation but how much shared state it has to touch. Interviewers ask this at the most senior levels because it tests whether someone can extract a design principle from an implementation detail and apply it to systems. In this answer, we will recap how balanced trees and skip lists stay balanced, see why rotations are hostile to concurrency, look at the cost of the skip list choice, and then apply the principle to system design.

1A Quick Recap: Two Ways to Stay Balanced

A sorted structure is only fast if it stays balanced, meaning paths from the top to any entry stay around log n steps long. A red-black tree, the structure inside TreeMap, enforces balance with rules about node colours. When an insert or delete breaks a rule, the tree fixes it by recolouring nodes and rotating, which means re-linking a parent, a child and a grandchild into a new shape. Fixing one place can break the rule one level up, so the repair can climb all the way to the root.

A skip list achieves balance on average without any repair. When a node is inserted, coin flips decide how many index levels it gets: half the nodes get one level, a quarter two, an eighth three, and so on. No existing node ever moves. Balance is a statistical property of all the coin flips together, not something maintained by restructuring.

2Why Rotations Are Hard to Make Concurrent

Think about what a rotation does to other threads. A thread searching the tree follows child pointers from the root. If another thread rotates the nodes it is passing through, the searcher can be led into the wrong subtree and miss a key that is present. To prevent that, a concurrent tree must lock the nodes involved in each rotation, and because rotations happen near the root as well as at the leaves, every writer competes for the same few top nodes. The root becomes a hot spot.

Lock-free designs make this worse. Lock-free algorithms change shared structure with compare-and-set, an instruction that atomically updates one memory word if it still has the expected value. A rotation changes three or more pointers that must all change together, and there is no compare-and-set for several words at once. Researchers have built concurrent balanced trees, with techniques like relaxed balancing or helping protocols, but they are intricate and hard to verify.

What one insert touches
Red-black treeSkip list
Nodes changedNew leaf plus recolours and rotations up the pathNew node plus a few index links
WhereCan reach the root, shared by every threadNext to the key only
Atomic unitSeveral pointers at onceOne pointer per compare-and-set
BalanceGuaranteed by repairExpected, by random levels

3Why the Skip List Fits Compare-and-Set

Inserting into a skip list is a sequence of independent single-pointer changes. First the new node is linked into the bottom level with one compare-and-set on its predecessor's next pointer. At that moment the key is in the map and visible to everyone. Then index nodes are added level by level, each with its own compare-and-set. If an index link fails because another thread changed that spot, the thread just retries locally; a missing index node only makes searches slightly slower, never wrong.

Deletion uses a similar trick: first mark the node as deleted, then unlink it, and any thread that sees a marked node helps finish the unlink. So two threads updating different keys almost never touch the same memory, and two threads updating neighbouring keys only conflict on a pointer or two. That locality is the entire reason Doug Lea's ConcurrentSkipListMap can be lock-free.

4What the Choice Costs

Nothing is free. Each entry needs its node plus, on average, about one extra index node, and each index node has its own object header and references, so a ConcurrentSkipListMap uses noticeably more memory per entry than a TreeMap. Searches follow more pointers through scattered objects, which is less friendly to CPU caches. And because balance is probabilistic, an individual operation can be slower than average; the expected cost is O(log n), but there is no hard bound per operation the way a red-black tree guarantees one.

The JDK team judged that a structure which is a bit slower per operation but scales almost linearly with threads is the better concurrent default. For single-threaded code, TreeMap remains the better choice, and the JDK keeps both.

5The General Lesson for Systems

The principle is this: under concurrency, the scalability of a design is limited by the shared state each update must touch. Structures and systems whose updates are local scale; those whose updates ripple through shared central points do not, however fast each step is.

We see it everywhere. ConcurrentHashMap locks one bin rather than the whole table, and LongAdder spreads a counter across cells. At system level, Kafka partitions a topic so producers and consumers of different partitions never coordinate. Databases shard by customer so most transactions touch one shard. A global sequence generator, a single leader that approves every write, or a distributed lock taken on every request is the system equivalent of rotating at the root. When we design, we ask of each frequent operation which shared things it has to touch, and push that number towards one local piece of state, accepting costs like more memory, probabilistic behaviour or weaker cross-partition guarantees in return.

Step throughThe same principle at every level
  1. CPUcompare-and-set on one word instead of a lock
  2. Data structureskip list links, one bin in ConcurrentHashMap, LongAdder cells
  3. Servicestate partitioned by key, no global lock per request
  4. PlatformKafka partitions, sharded databases, per-region control

4 layers, from the top down. Step through them one at a time.

6Follow-up questions

Does a skip list ever degrade badly?

Only with extremely bad luck in the random levels, which becomes vanishingly unlikely as the map grows; the expected cost stays O(log n). It is not vulnerable to adversarial key orders the way an unbalanced binary tree is, because the levels do not depend on the keys.

Are there concurrent B-trees in practice?

Yes, databases use them heavily, with techniques like latch coupling and B-link trees that let readers pass splitting nodes. They work well because pages are large and splits rarely reach the root, which is the same idea again: keep most updates local.

How would you apply this lesson in a design review?

For each high-frequency operation, list the shared resources it touches: locks, rows, counters, leaders, caches. Anything touched by every request is a future bottleneck, so we look for a way to partition it, make it append-only, or move it off the hot path.

7Conclusion

In this answer, we saw why the JDK's concurrent sorted map is a skip list. Balanced trees rebalance with rotations that can climb to the root and change several pointers at once, so concurrent updates contend on shared nodes and resist lock-free implementation. Skip list updates are local and probabilistic, made of single-pointer compare-and-set steps, at the cost of more memory per entry and less predictable per-operation time. The lesson generalises: prefer structures and system designs where updates touch little shared state, because partitioning and local updates scale better than global coordination.

What to say in the interviewAbout 100 seconds aloud

Open with

A balanced tree like a red-black tree stays balanced by repairing itself: after an insert or delete it recolours and rotates nodes, and that repair can climb all the way up to the root.

Then, if they want more

For concurrency that's bad in two ways. Every writer may need to touch nodes near the top, so they contend on the same few nodes, and a rotation changes several pointers that must change together, which you can't do with a single compare-and-set, so a lock-free version is very hard to build and verify.

A skip list gets its balance from randomness instead: when you insert, coin flips decide how many index levels the node gets, and nothing existing ever moves. An insert is a handful of single-pointer compare-and-set operations next to the key, so threads working on different keys barely interact. That's why Doug Lea could make ConcurrentSkipListMap lock-free.

The trade-off is more memory per entry because of the index nodes, worse cache locality, and only expected log n cost rather than a guaranteed bound. The general lesson I take is that under concurrency, what limits scaling is how much shared state each update touches, not how fast the operation is.

You see the same thing with ConcurrentHashMap's per-bin locks and LongAdder, and at system level with Kafka partitions or sharded databases. In design reviews I look for anything every request has to touch, like a global lock or a single counter, and try to partition it or make it local.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The JDK provides a concurrent sorted map built on a skip list (ConcurrentSkipListMap)...": https://scrivio-interview-library.netlify.app/java/concurrent-collections/6fc5667cbf/