Tech News
← Back to articles

From Rust to reality: The hidden journey of fetch_max

read original related products more articles

QuestDB is the open-source time-series database for demanding workloads—from trading floors to mission control It delivers ultra-low latency, high ingestion throughput, and a multi-tier storage engine. Native support for Parquet and SQL keeps your data portable, AI-ready—no vendor lock-in.

I occasionally interview candidates for engineering roles. We need people who understand concurrent programming. One of our favorite questions involves keeping track of a maximum value across multiple producer threads - a classic pattern that appears in many real-world systems.

Candidates can use any language they want. In Java (the language I know best), you might write a CAS loop, or if you're feeling functional, use updateAndGet() with a lambda:

AtomicLong highScore = new AtomicLong(100); [...] highScore.updateAndGet(current -> Math.max(current, newScore));

But that lambda is doing work - it's still looping under the hood, retrying if another thread interferes. You can see the loop right in AtomicLong's source code.

Then one candidate chose Rust.

I was following along as he started typing, expecting to see either an explicit CAS loop or some functional wrapper around one. But instead, he just wrote:

high_score.fetch_max(new_score, Ordering::Relaxed);

"Rust has fetch_max built in," he explained casually, moving on to the next part of the problem.

Hold on. This wasn't a wrapper around a loop pattern - this was a first-class atomic operation, sitting right there next to fetch_add and fetch_or . Java doesn't have this. C++ doesn't have this. How could Rust just... have this?

... continue reading