Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Your services exchange large numeric datasets and repeatedly convert between primitive arrays, boxed collections, byte buffers and JSON, which shows up as a major CPU and GC cost. What long-term direction do you set?

First I make the cost visible at fleet level with async-profiler and JFR allocation profiling, so we know which conversions cost how much CPU and memory. Then I set the direction: binary formats such as Protobuf, Apache Arrow or Parquet at service boundaries instead of JSON for large numeric data, primitive arrays or columnar structures inside hot paths with no boxing, and shared libraries and guidelines so teams stop reinventing conversions. Project Valhalla's value classes should reduce boxing in the future, and we track them, but we do not plan on a delivery date that has not been announced.

Why this question is asked

When numeric data moves through several services, each hop tends to convert it twice: from the service's internal arrays to a boxed List<Double> for a framework, to JSON text for the wire, and back again on the other side. Each conversion is cheap on its own and invisible in code review, but at scale they add up to a large share of CPU and garbage collection. Interviewers ask this as a leadership question because the fix is not one clever change but a direction that many teams follow over a year or more. In this answer, we will recap why these conversions are expensive, see how to measure them across the fleet, choose representations for the wire and for memory, look at what Valhalla may change, and set up the guidelines and shared libraries that make the direction stick.

1A Quick Recap: Why These Conversions Cost So Much

A double[] of one million prices is one object of about 8 MB. The same data as a List<Double> is one million separate Double objects, each 16 bytes plus a 4 or 8 byte reference in the list, so roughly 24 MB, scattered across the heap, and every one of them must be allocated, traced by the garbage collector and eventually collected.

Text formats add another layer. Writing a double as JSON means formatting it as decimal text, often 15 to 20 characters, and reading it back means parsing that text, which is one of the more expensive things a CPU does per byte. A million prices become around 20 MB of JSON, which is more bytes on the network than the 8 MB of raw data, then it is parsed into boxed objects again on the receiving side. Each step allocates, which drives up GC frequency across every service involved.

Step throughOne dataset crossing one service boundary today
  1. double[] in service A8 MB, one object
  2. Boxed List<Double>1,000,000 objects, about 24 MB
  3. JSON textabout 20 MB of decimal strings
  4. Parsed List<Double> in service Banother million objects
  5. Back to double[] for computationone more full copy

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

Every highlighted step allocates and copies the whole dataset.

2Measuring the Cost Across the Fleet

A direction that asks many teams to change their code needs evidence. So the first step is to measure. JFR, the JDK's built-in flight recorder, records allocation samples with stack traces at low overhead and can run continuously in production. async-profiler produces CPU and allocation flame graphs that show where time and memory go. We run these on representative instances of the busiest services and aggregate the results by frame, looking for JSON serialisation, Double.valueOf, ArrayList growth and stream boxing.

The goal is a number leaders can act on, such as: 30 percent of CPU across the pricing services goes to serialisation and boxing, and 60 percent of allocated bytes come from the same paths. That number turns an engineering preference into a cost case, and it also tells us which few services matter most, so we start there.

3Choosing Formats at Service Boundaries

For large numeric data, binary formats beat JSON by large factors in both size and CPU. The right choice depends on the shape of the data and how it is used, so the direction names a small set of approved options rather than one format for everything.

Approved representations by use
UseRepresentationWhy
Request and response messagesProtobuf with packed repeated fieldscompact, schema-checked, fast to parse
Large tables between servicesApache Arrowcolumnar, near zero-copy, no per-value objects
Data at rest, analyticsParquetcolumnar, compressed, read by data tools
Small, human-facing APIsJSONreadable, fine when data is small

Protobuf encodes a repeated double field as packed 8-byte values, so a million prices take about 8 MB on the wire, and generated code can read them without parsing text. Arrow goes further for tabular data: its columns are contiguous buffers, so a service can hand a dataset to another process or a data tool with little or no conversion. Parquet suits storage and batch processing. JSON stays where it shines, for small, human-facing payloads. The change is introduced per boundary, starting with the heaviest ones the profiles found, usually by adding a binary endpoint alongside the JSON one and moving consumers over.

4Keeping Hot Paths Primitive

Inside a service, the rule is that hot computation runs on primitive arrays or columnar structures, and boxing is allowed only at the edges where a framework demands it. When teams need collections of primitives, such as a map from instrument id to price, libraries with primitive collections, such as fastutil or Eclipse Collections, provide an IntDoubleMap-style type that stores ints and doubles directly without boxing.

Java
// Before: boxing on every element
List<Double> prices = loadPrices(); // one Double per value
double total = prices.stream().mapToDouble(Double::doubleValue).sum();
// After: primitive all the way through the hot path
double[] prices = loadPrices(); // one object, 8 bytes per value
double total = 0;
for (double p : prices) total += p; // no allocation at all

The change looks small in one method, but the effect compounds: no Double objects means less allocation, fewer young collections, better cache use and simpler conversions to binary formats, since a double[] maps directly to a packed Protobuf field or an Arrow column.

5Tracking Valhalla Without Betting on Dates

Project Valhalla aims to add value classes to Java: types without object identity that the JVM can store flat in arrays and fields, and eventually to let generic code work with them more efficiently. If that arrives, a List-like structure of value types could avoid much of today's boxing cost. That is an important direction for exactly this problem.

But as of Java 25, value classes are not part of the released platform, and no delivery date has been committed, so check the current status when planning. A leader's job here is to keep the organisation ready, for example by keeping representation choices behind shared library APIs so they can change in one place, and by assigning someone to follow Valhalla's early-access builds and report what would change for us. We do not tell teams to wait for it, and we do not put it in a roadmap with a date.

6Guidelines and Shared Libraries So Teams Do Not Reinvent It

The direction becomes real through shared tools. A small internal library provides the approved conversions in one place: double[] to and from Protobuf packed fields, Arrow vectors to primitive arrays, a streaming JSON writer for the cases where JSON stays. Each conversion is tested, benchmarked and owned by a platform team, so service teams call one method instead of writing their own loops and getting edge cases such as NaN or infinity wrong.

Short guidelines explain the rules and the reasons: binary formats for numeric payloads above a threshold such as 100 KB, no boxed collections in hot paths, use the shared converters. We track progress with the same profiles that made the case, re-run every quarter, so teams and leadership can see CPU and GC cost falling, and we adjust the guidance where it does not fit real cases.

7Follow-up questions

How do you convince teams to change formats that already work?

With their own numbers. The fleet profile shows each team how much CPU and memory their service spends on conversions, and the shared library makes the change small. We start with the services where the gain is largest, publish the before and after results, and let those results carry the next teams.

Is JSON ever acceptable for numeric data?

Yes, when the data is small, human-facing or consumed by tools that only speak JSON. A response with ten numbers does not justify a binary format. The guideline uses a size threshold so the decision is simple, and it applies to new and heavy boundaries first.

What about the cost of migrating existing consumers?

We add binary endpoints alongside existing JSON ones, move consumers one at a time, and only remove the JSON path when traffic on it has stopped. This keeps every step reversible and avoids coordinated big-bang releases across teams.

8Conclusion

In this answer, we treated conversion overhead as an organisational problem. We measure it fleet-wide with JFR and async-profiler to make the cost case, choose binary formats such as Protobuf, Arrow and Parquet at boundaries for large numeric data instead of JSON, keep hot paths on primitive arrays or columnar structures with primitive collections where maps are needed, track Valhalla's value classes without planning on undelivered dates, and make the direction stick with shared, tested conversion libraries, short guidelines and regular re-measurement.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by making the cost undeniable. I'd run JFR allocation profiling and async-profiler on the busiest services and aggregate where CPU and allocated bytes go, so we can say something like: a third of CPU in these services is serialisation and boxing.

Then, if they want more

That turns this from an opinion into a business case and tells us which boundaries to fix first. Then I'd set a direction with three parts. At service boundaries, large numeric data moves in binary formats, Protobuf with packed fields for messages, Arrow for big tables, Parquet for data at rest, and JSON stays for small, human-facing payloads.

Inside services, hot paths use primitive arrays or columnar structures, and if teams need maps or lists of primitives, they use a primitive collections library rather than boxed collections. And third, a platform team owns a shared library of tested, benchmarked converters, so teams don't each write their own loops and get NaN handling wrong.

I'd also follow Project Valhalla, since value classes aim to cut exactly this boxing cost, but they're not in Java 25, so I'd keep representations behind shared APIs and not put Valhalla on a roadmap date. Finally, I'd re-run the same profiles every quarter so everyone can see the cost going down.

About this answer

Last updated
12 November 2026
Versions it names
Java 25
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 "Your services exchange large numeric datasets and repeatedly convert between primitive...": https://scrivio-interview-library.netlify.app/java/arrays/90b209092d/