Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Containers made local disks short-lived, and object storage replaced many shared file systems. How has this changed the role of file I/O in Java services, and what guidance would you give teams over the next years?

In containers the local disk lives only as long as the container, so local files are now only for caches and temporary data, and durable data belongs in object storage or a database. Shared file systems such as NFS bring locking and change-notification problems that object storage avoids. My guidance is to put durable storage behind a small internal interface so files and object stores can be swapped, to stream large data rather than load it into memory whatever the backend, and to keep using Files and Path, with explicit charsets and closed resources, for the local work that remains.

Why this question is asked

Many Java services were designed when a server was a long-lived machine with a disk that kept its contents for years, and sometimes a shared network drive. Containers and cloud platforms changed those assumptions: a pod can be rescheduled at any moment and its disk disappears with it, while object storage such as Amazon S3, Google Cloud Storage or Azure Blob Storage became the default place for files. Interviewers ask this at a senior level to see whether we can explain how the role of file I/O shifted and give teams guidance that will hold for years. In this answer, we will look at what containers did to local disk, why shared file systems fell out of favour, what an abstraction for storage should look like, why streaming still matters, and what remains of plain file I/O.

1A Quick Recap: Three Kinds of Storage

A container's local file system is a writable layer on top of its image, plus any temporary volumes such as Kubernetes emptyDir. It is fast, but when the container is replaced, which happens on every deployment, scaling event or node failure, its contents are gone. A shared file system, such as NFS or SMB, is mounted by many machines and looks like an ordinary directory. Object storage is a service that stores whole objects, blobs of bytes with a key and metadata, accessed through an HTTP API; objects are written and replaced as a whole, not edited in place.

Where data can live, and what it suits
StorageLifetimeGood forWatch out for
Container local diskuntil the container is replacedcaches, temp files, scratch spacelost on every restart or reschedule
Persistent volumebeyond the pod, tied to one zonedatabases, single-writer statemoves slowly, one writer at a time
Shared file system (NFS)longlegacy integrationslocking, stale caches, no reliable events
Object storagelong, replicateddocuments, exports, archives, data lakeswhole-object writes, network latency

2Local Files Became Temporary

The first change is that we can no longer treat the local disk as storage. A service that writes uploaded documents to /data/uploads works perfectly until its first redeploy, and then the files are gone. With two replicas it is worse, because each replica sees only the files it wrote, so a request routed to the other replica fails. So local files are now only for data we can lose and rebuild: caches, intermediate files during a job, extraction of an archive before processing, and buffers. Anything that must outlive the container goes to a database, object storage or a persistent volume chosen on purpose.

3Why Shared File Systems Fell Out of Favour

The traditional answer to sharing files between servers was a network file system, and it still exists in many integrations. But it brings problems that are easy to underestimate. File locks over NFS depend on extra lock services and behave differently between versions and clients. Change notifications such as WatchService often do not work on network mounts, because the notifications are generated by the local kernel, which does not see changes made by other clients. Client caching can make one machine see stale data for seconds. And when the file server is slow or unavailable, every process that touches the mount can hang in uninterruptible I/O.

Object storage avoids most of this by having a simpler model. Writes replace whole objects atomically, there are no locks, reads go over HTTP with clear timeouts and errors, and storage is replicated and effectively unlimited. Major providers now offer strong read-after-write consistency. Events for new objects are delivered as messages to a queue, which is more reliable than file-system notifications. The trade-off is that we cannot append to or edit an object in place and each call has network latency, so the code must be written for that model.

4Put Storage Behind a Small Interface

The guidance that follows is to stop calling Files or a cloud SDK directly from business code for durable data. Instead each service depends on a small interface that describes what it needs, and an implementation decides where the bytes go. This lets us use a local directory in development and tests, object storage in production, and migrate between providers without touching the business logic.

Java
public interface DocumentStore {
void put(String key, InputStream content, long length, String contentType) throws IOException;
InputStream get(String key) throws IOException; // caller closes; streams, never byte[]
boolean delete(String key) throws IOException;
Stream<String> list(String prefix) throws IOException; // caller closes
}
class LocalDocumentStore implements DocumentStore { /* Files, Path, a base directory */ }
class S3DocumentStore implements DocumentStore { /* AWS SDK; multipart upload for large objects */ }

Notice that the interface follows the object-storage model, whole objects identified by keys, rather than the file model with appends and renames. That is deliberate: it is easy to implement object semantics on a local disk, but hard to implement file semantics on object storage. We keep the interface small and specific to the domain, rather than building a general virtual file system, because a narrow interface is easier to implement correctly twice.

5Stream Large Data, Whatever the Backend

Moving to object storage does not remove the need to think about memory. A 3 GB export loaded into a byte array fails just as badly from S3 as from a local file. So the guidance is that large data flows as streams: the interface takes and returns InputStreams, uploads of large objects use the SDK's multipart upload, and processing reads records incrementally. With virtual threads, the blocking streaming code is simple and still scales to many concurrent transfers. A useful habit is to review any method that returns byte[] or String for content that is not bounded in size.

6What Remains of Plain File I/O

Local file I/O does not disappear; it becomes a tool for the work inside one container. There, the established rules still apply: use Files and Path, pass StandardCharsets.UTF_8 explicitly, close every stream with try-with-resources, write temporary files into a directory meant for them, and clean them up. Container-specific rules join them: size temporary volumes so a large job cannot fill the node's disk, and remember that writing to the container's writable layer is slower than an emptyDir volume, so heavy scratch work belongs on a volume.

7Follow-up questions

Are there still good reasons to use a shared file system?

Yes, a few. Some third-party tools and legacy integrations can only read and write files, and some workloads, such as certain machine learning and media pipelines, need a POSIX file view of large shared data sets. In those cases we choose a managed file service on purpose, document its locking and consistency behaviour, and keep the shared directory away from the core transactional path.

How do you migrate an existing service that writes to local disk?

First, introduce the storage interface with a local implementation, so behaviour does not change while the code moves behind it. Then add the object-storage implementation, copy existing files with a one-off job, and switch with a configuration flag, ideally reading from both for a transition period. Finally remove the local path and the persistent volume once nothing reads from them.

8Conclusion

In this answer, we saw that containers made local disks short-lived, so local files now suit only caches and temporary data, and that shared file systems bring locking, notification and caching problems that object storage avoids with its whole-object model. The guidance for teams is to put durable storage behind a small, object-shaped interface, stream large data on every backend, and keep using Files and Path with explicit charsets and closed resources for local work.

What to say in the interviewAbout 90 seconds aloud

Open with

The big change is that the local disk stopped being storage. In a container, the file system is gone whenever the pod is replaced, which happens on every deploy or reschedule, and with several replicas each one only sees its own files.

Then, if they want more

So I tell teams local files are only for caches, temporary files and scratch space, and anything durable goes to a database, object storage or a deliberately chosen persistent volume.

Shared file systems like NFS used to be the way to share files, but they bring real problems: locking is unreliable, WatchService notifications usually do not arrive for changes made by other machines, caching can show stale data, and a slow file server can hang every process using it.

Object storage has a simpler model: whole objects replaced atomically, HTTP with clear errors and timeouts, replication, and change events delivered as messages.

My guidance is to put durable storage behind a small domain interface, something like a DocumentStore with put, get, delete and list by key, shaped like object storage, with a local implementation for tests and an object store implementation for production. Large data should always stream, using InputStreams and multipart uploads, never byte arrays, whatever the backend.

And for the local file work that remains, the old rules still hold: Files and Path, explicit charsets and try-with-resources.

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 "Containers made local disks short-lived, and object storage replaced many shared file...": https://scrivio-interview-library.netlify.app/java/io-and-nio/7b25907fbc/