Scrivio Interview library
ConceptPrincipal7 min read · updated 12 November 2026

Core counts keep rising, ARM servers are common, and NUMA effects matter on large machines. Over the next decade, which concurrency approaches should your organisation prefer: locks, atomics and lock-free structures, or designs based on partitioning and message passing? Explain your reasoning.

I would steer the organisation toward designs that minimise sharing: partition data by key so each thread or shard owns its state, and use message passing where ownership must move, because shared mutable state on hot paths scales poorly with more cores, ARM and NUMA whether it is guarded by locks or atomics. Locks and atomics remain the right tools for low-contention shared state, where they are simpler to read than any alternative. Lock-free code should live inside well-tested libraries, not in application code.

Background to this question

Hardware trends change which concurrency designs age well. Ten years ago a large server had a couple of dozen cores; now 128 or more is ordinary, often across several NUMA nodes, and ARM servers with weaker memory ordering run a growing share of workloads. A principal engineer is asked this because the choice of default patterns affects every team for years. In this answer, we will explain why shared state hits a wall regardless of the tool, look at partitioning and message passing as alternatives with their costs, keep locks and atomics in their proper place, and set out a stance with the reasoning behind it.

1Why Shared Mutable State Hits a Wall

Every write to shared memory needs the writing core to own that memory's cache line exclusively. If many cores write the same variable, or variables on the same 64-byte line, the line travels between them, and every write waits for the transfer. On one socket that costs around a hundred nanoseconds; across NUMA nodes, where memory and caches belong to different sockets or chiplets, it costs more. The crucial point is that this cost does not depend on whether we used a lock, a synchronized block, an AtomicLong or a clever lock-free structure. All of them write shared memory, so all of them serialise on the line. A lock adds waiting, and a CAS loop adds retries, but the root cost is the sharing itself.

ARM adds a second pressure. Its memory model allows more reordering than x86, so code with a subtle missing happens-before relationship that works on x86 can fail on ARM. Java's memory model protects correctly synchronised code everywhere, but home-grown lock-free code is exactly where such mistakes hide. So as core counts rise and ARM spreads, hand-written shared-state concurrency gets both slower and riskier.

2Partitioning: Give Every Piece of State One Owner

The alternative is to arrange that each piece of mutable state is touched by only one thread or one shard. If orders are partitioned by customer id into 32 shards, each with its own thread and its own data, the shards never contend: no locks, no atomics, no cache line transfers on the hot path. This is the idea behind Kafka's partitions consumed by one consumer each, behind thread-per-core servers, and behind per-thread buffers that are merged occasionally, like LongAdder's cells taken to the level of whole services.

Partitioning has real costs. Work that spans keys, such as a transfer between two customers in different shards, needs coordination, a two-step protocol or a different design. Skewed keys create hot shards, so one very large customer can saturate one thread while others are idle. And rebalancing shards when the number of nodes changes needs care. These costs are manageable and visible, though, unlike contention, which grows silently with core counts.

Java
// Each shard owns its state; one thread per shard, so no locks inside
final class Shard implements Runnable {
private final Map<String, Account> accounts = new HashMap<>(); // plain HashMap, single owner
private final BlockingQueue<Command> inbox = new ArrayBlockingQueue<>(10_000);
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try { inbox.take().applyTo(accounts); } // commands applied one by one
catch (InterruptedException e) { return; }
}
}
}
Shard shardFor(String customerId) {
return shards[Math.floorMod(customerId.hashCode(), shards.length)]; // same key -> same owner
}

3Message Passing: Making Ownership Explicit

When state must be used by more than one component, message passing moves ownership instead of sharing it. A component owns its state and other components send it messages through a queue; only the owner reads or writes the state. The example above is a small instance: shards receive commands through their inbox. Actor frameworks such as Akka (and its fork Apache Pekko), event streams with Kafka, and channels between pipeline stages all apply the same idea at different scales.

The benefit is that every piece of state has a clear owner, so reasoning about concurrency becomes reasoning about the order of messages, which is far easier to review. The cost is latency, because every interaction includes a queue hop, and complexity elsewhere: back pressure when a queue fills, failure handling when an owner crashes, and request-response patterns that need correlation. For a hot path with nanosecond budgets, a queue hop per operation can be too slow, which is why message passing usually works at the level of batches or whole requests.

Concurrency approaches compared
ApproachScales with coresMain cost
Locks on shared statePoorly when contendedWaiting; deadlock risk
Atomics and CASPoorly when contendedCache line transfers, retries
Custom lock-free structuresSomewhat; still sharedHard to prove correct, ARM bugs
Partitioning by keyWellCross-key work, hot keys
Message passingWellQueue latency, back pressure

4Where Locks and Atomics Still Belong

None of this makes locks or atomics obsolete. Most shared state in a business service is not on a hot path at all: a configuration holder, a cache refreshed every minute, a connection registry. Contention there is negligible, and a synchronized block or an AtomicReference is the simplest correct code anyone can read. Replacing it with shards or actors would add complexity for no benefit. Virtual threads in recent Java versions also favour plain blocking code with simple locks, and since Java 24 synchronized no longer pins virtual threads in the common cases, so the simple style is cheaper than ever.

5The Stance I Would Take

The guidance I would write for the organisation follows from those trade-offs. Design to minimise sharing: when state is hot, partition it by key, or give it a single owner and send it messages. Use locks and atomics freely for state that is rarely contended, preferring the simplest correct form. Keep lock-free code inside well-tested libraries, the JDK's java.util.concurrent, JCTools, Micrometer, Caffeine and similar, and require a strong case and expert review for any new lock-free code in application repositories.

Two supporting practices make the stance real. Run performance tests on the hardware we deploy to, including ARM instances and large multi-socket machines, because contention and ordering bugs only appear there. And measure contention, with JFR's lock and monitor events or async-profiler's lock mode, so teams find hot shared state from data rather than guesswork.

Step throughChoosing a design for shared state
  1. Is this state on a hot path with many writers?
    YesNext questionNoLock or atomic, simplest form
  2. Can it be split by key?
    YesPartition: one owner per shardNoNext question
  3. Can one owner serve it through messages?
    YesSingle owner with a queueNoProven concurrent library, measured

3 steps in order. Play them, or step through them one at a time.

6Follow-up questions

Does NUMA matter for Java applications in practice?

On large machines, yes. A shared variable written from cores on different NUMA nodes costs more per transfer, and memory allocated on one node is slower to access from another. Partitioning by key, with each shard's threads and memory local to a node, is the design that benefits; the JVM's NUMA-aware allocation options help but do not fix shared hot variables.

Are actors the answer then?

They are one way to express single ownership, with good tooling for supervision. They also bring their own costs: message overhead, harder debugging of flows and a framework to learn. Plain partitioned executors or Kafka partitions give the same ownership benefits in many services with less machinery.

How do virtual threads change the picture?

They make blocking cheap, which favours simple code with locks for low-contention state and thread-per-request designs. They do not remove cache line contention: a million virtual threads updating one AtomicLong still serialise on it, so the partitioning advice is unchanged.

7Conclusion

In this answer, we saw that shared mutable state on hot paths scales poorly with rising core counts, NUMA and ARM no matter whether locks, atomics or lock-free structures guard it, because the cost is the sharing itself. Partitioning state by key gives each piece one owner and avoids contention, at the cost of cross-key work and hot keys; message passing makes ownership explicit, at the cost of latency and complexity. Locks and atomics remain right for low-contention state, and the stance is to minimise sharing, keep lock-free code inside libraries, and test and measure on the hardware we run.

What to say in the interviewAbout 90 seconds aloud

Open with

My reasoning starts from the hardware. Any write to shared memory needs exclusive ownership of a cache line, so when many cores write the same state, the line bounces between them, and that cost grows with core counts and with NUMA distance.

Then, if they want more

It doesn't matter whether that state is guarded by a lock, an atomic or a lock-free structure; they all share memory, so they all hit that wall. ARM adds risk because its weaker memory ordering exposes subtle bugs in hand-written lock-free code that x86 hides. So for hot state, I'd push teams toward minimising sharing.

The first tool is partitioning by key: each shard or thread owns its data, uses plain non-concurrent structures, and there's no contention at all, like a Kafka partition per consumer or shards chosen by customer id. The costs are cross-key operations and hot keys, but they're visible and manageable.

The second is message passing, where state has one owner and others send it messages, which makes ownership explicit but adds a queue hop of latency and needs back pressure.

Locks and atomics stay the right answer for low-contention shared state, which is most state in a business service, because they're the simplest code to read, and virtual threads make plain blocking code even cheaper. And I'd keep lock-free code inside proven libraries like java.util.concurrent, JCTools or Caffeine, with performance tests on the ARM and large machines we actually run.

About this answer

Last updated
12 November 2026
Versions it names
Java 24
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 "Core counts keep rising, ARM servers are common, and NUMA effects matter on large...": https://scrivio-interview-library.netlify.app/java/atomics/899160cd88/