Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Several teams want to build custom storage engines in Java using memory-mapped files and off-heap memory for speed. Over a multi-year horizon, when is building such infrastructure justified, and when should the company buy or adopt an existing engine?

Building a storage engine is justified only when the workload is core to the business, existing databases and embedded stores have been measured and shown to fail it, and the company commits owners for the engine's whole life. A real engine needs years of work on durability, crash recovery, compaction and tooling that existing engines have already done and tested widely. So the default is to adopt, and the first step for any team is to prototype on an existing engine to set a performance baseline that a custom build must clearly beat.

Why this question is asked

Memory-mapped files and off-heap memory make it tempting to write a storage engine in Java: a first prototype can be faster than a general database within a few weeks. The trouble is that the prototype covers perhaps a tenth of what a storage engine must do, and the remaining work arrives slowly as incidents over years. When several teams want to do this at once, the decision becomes an organisational one about where engineering effort goes. Interviewers ask this at the most senior level to see how we weigh speed against long-term cost and risk. In this answer, we will look at what a storage engine really has to do, what existing engines give us, the conditions under which building is justified, the people cost, and how I would run the decision with the teams.

1A Quick Recap: What a Storage Engine Must Do

A storage engine is the part of a database that stores and retrieves data on disk. The fast path, writing records and finding them again, is the visible part. Underneath, it must be durable, meaning a write that was acknowledged survives a crash or power loss, which requires careful use of fsync and a write-ahead log. It must recover after a crash, replaying or discarding half-finished work and detecting corruption with checksums. It must reclaim space through compaction or garbage collection of old versions without stalling foreground traffic. It must handle concurrency between readers and writers, and it needs backup, restore, replication, upgrades of its on-disk format, metrics and debugging tools.

Each of those has subtle failure modes that appear only under rare timing, full disks, kernel bugs or hardware faults. Mature engines found them through years of production use by many companies and through testing techniques like fault injection and randomized crash testing.

The visible part and the rest
AreaIn a first prototype?Effort to reach production grade
Fast reads and writesyesweeks
Durability and write-ahead logpartlymonths, plus crash testing
Crash recovery and corruption checksrarelymonths, never really finished
Compaction without latency spikesnomonths to years of tuning
Backup, restore, replicationnomonths each
Format upgrades, tooling, metricsnoongoing for the engine's life

2What Adopting Gives Us

Existing engines, from PostgreSQL to embedded stores such as RocksDB, LMDB, SQLite and H2, and Java-native caches and off-heap stores, have already solved those problems and have been tested at a scale no single team can match. They come with documentation, operational knowledge that new hires already have, tuning guides and communities that report and fix bugs. Their weaknesses are known and published. Adopting one shifts our work from building infrastructure to configuring and operating it, which is a far smaller and more predictable cost.

A general engine may be slower than a custom one for a specific access pattern. But the comparison that matters is not peak speed in a benchmark; it is whether the existing engine meets the requirement, at what hardware cost, compared with the total cost of building and owning an alternative.

3When Building Is Justified

I would support building when three conditions hold together. First, the workload is core to the business, so storage performance or behaviour is a competitive advantage or a hard requirement, such as a trading system's market data store or a search product's index. Second, existing options have been measured on realistic data and hardware and fail the requirement by a clear margin, for example a p99 latency target of 200 microseconds that the best tuned embedded store misses by five times, or hardware costs that would be several times higher. Third, the company is willing to fund the engine as a product, with a team that owns it for its whole life.

If any of these is missing, building is usually a mistake. A non-core workload does not justify years of specialist effort. An unmeasured belief that existing engines are too slow is often wrong once they are tuned. And an engine without long-term owners becomes a critical system that nobody understands.

Step throughBuild or adopt
  1. Prototype on an existing enginesets the baseline
  2. Does it meet the requirement after tuning?
    Yesadopt itNocontinue
  3. Is the workload core to the business?
    YescontinueNoadopt and relax the requirement or add hardware
  4. Will we fund a team for its lifetime?
    Yesbuild, with a narrow scopeNoadopt the closest engine

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

4The People Cost Over Years

The cost that teams underestimate most is people. A storage engine needs engineers who understand file systems, fsync semantics, memory mapping, the JVM's off-heap behaviour and concurrency at a deep level. These people are rare and expensive, and if the two who wrote the engine leave, the company holds a critical system it cannot safely change. Every new feature the business asks for, such as encryption at rest, a new index type or multi-region replication, becomes an engine project. A useful exercise is to estimate the cost over five years: a dedicated team of three to five specialists, on-call duty, and the incidents that come with young storage code, against the hardware or licence cost of the adopted alternative. The adopted engine usually wins by a wide margin unless the workload truly is at the core of the business.

5How I Would Run the Decision

With several teams asking at once, I would not decide case by case in hallway conversations. I would ask each team for a short proposal that states the requirement in numbers, shows a prototype on at least one existing engine as the baseline, explains what custom work would beat it and why, and names who would own it. That prototype matters most: it often shows the existing engine is good enough, and if it is not, it gives the custom build a clear target to beat.

If two teams have similar needs, we should not build two engines; one shared component, owned by a platform team, is better. If we do build, the scope should stay narrow, such as a read-only memory-mapped index rebuilt from a database, which avoids the hardest parts like crash recovery of in-place writes. And we write down the conditions under which we would retire it in favour of an off-the-shelf engine, so the decision is revisited as the market changes.

6Follow-up questions

Is it ever reasonable to build a small engine for learning or speed of delivery?

A narrow, rebuildable component is reasonable, such as a read-only index file generated from the system of record and memory-mapped for lookups. If it is lost or corrupted, we regenerate it, so it avoids durability and recovery entirely. What I would avoid is letting such a component quietly grow writes, updates and replication until it becomes a database without anyone deciding that it should.

How do you handle a team that is sure the custom engine will be faster?

I take the claim seriously and ask for the measurement. A two-week prototype on RocksDB or the existing database, tuned with help from someone who knows it, either confirms the gap or closes it. If the gap is real and the workload is core, the team has a strong case and I support it. If not, the data makes the decision without it becoming a matter of opinion.

7Conclusion

In this answer, we saw that a storage engine is much more than fast reads and writes: durability, crash recovery, compaction, backup, upgrades and tooling take years and are already solved by existing databases and embedded stores. Building is justified only when the workload is core to the business, existing engines measurably fail it, and the company funds owners for the engine's lifetime. Every proposal should start with a prototype on an existing engine to set the baseline.

What to say in the interviewAbout 90 seconds aloud

Open with

My default would be to adopt, and to treat building as an exception that has to earn its place. The reason is that the fast path of a storage engine is the easy part.

Then, if they want more

The hard parts are durability, crash recovery, corruption detection, compaction that does not cause latency spikes, backup, replication, format upgrades and tooling, and those take years and only mature with wide production use. RocksDB, LMDB, PostgreSQL and the established caches have already done that work.

I would support building when three things are all true: the workload is core to the business, the existing options have been measured on real data and clearly miss the requirement, and we are willing to fund a team that owns the engine for its whole life.

The people cost is what gets underestimated; it needs rare specialists, on-call, and every new feature becomes an engine project, so I would compare five years of that with the hardware or licence cost of the alternative.

Practically, I would ask each team for a short proposal with the requirement in numbers and a prototype on an existing engine as a baseline, because that prototype often shows the existing engine is fine. If several teams have the same need, we build one shared component, not several.

And if we build, I would keep the scope narrow, like a read-only mapped index rebuilt from the database, which avoids the hardest recovery problems.

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 "Several teams want to build custom storage engines in Java using memory-mapped files and...": https://scrivio-interview-library.netlify.app/java/io-and-nio/86bfb31f5d/