Storing large Binary files on the filesystem in HAPI FHIR

Learn when the HAPI FHIR JPA starter should keep large Binary payloads on disk instead of in the database, and what configuration, backup and permission work comes with it.

On this page

When should HAPI FHIR store large Binary files on the filesystem?

Move large Binary payloads out of the database when documents, images or other big attachments are inflating the database, slowing backups and restores, and growing faster than the clinical data around them. The HAPI FHIR JPA starter offers filesystem binary storage: set binary_storage_mode to FILESYSTEM and the starter streams large Binary payloads to a directory on disk instead of holding them in the relational database. The starter README describes this as the mechanism for large payloads, so it is the setting to evaluate first before redesigning storage around object storage or an external document system.

Size matters in one specific way. If inline_resource_storage_below_size is omitted, payloads under 102400 bytes (100 KB) stay in the database, and only larger payloads go to disk. Check your real payload distribution before choosing this default. If most attachments are small, such as scanned forms under 100 KB, they will still drive database growth, and you may need to set the threshold explicitly. Ask your team to pull a size histogram of Binary resources from a staging copy of the database so the threshold reflects actual data, not assumptions.

Before you commit, confirm two operational facts with your own environment. The directory must be writable by the process running the server, so check the permissions for the account that runs the container, WAR or service on each node. Also confirm who owns backups: database backups will no longer capture the file contents, so the filesystem directory needs its own backup, retention and restore test, and the database and files must be restored to a consistent point. Multi-instance deployments need a shared or otherwise agreed location for the directory, which should be settled during design rather than after go-live.

Which storage mode fits each workload

Binary resources below the inline threshold stay in the relational database, in the same transactions and backups as the rest of the FHIR data. For the starter, this is the default behavior when inline_resource_storage_below_size is omitted, and it keeps the number of moving parts low. Small consent forms, thumbnails, signed PDFs and other short attachments usually fit this model well, because the database already handles their lookup, versioning and deletion.

  • One backup set: A single database dump or snapshot covers the resources and their small binaries, so restores do not need a second store to be reconciled.
  • Database growth: Every inline payload adds to table size, index maintenance and replication volume. Watch growth on the database side rather than assuming it is free.
  • Simple permissions: Access flows through the FHIR authorization layer only, with no separate file path to protect.
  • Threshold choice: The default is 102400 bytes (100 KB). Confirm the threshold against your document mix before go-live, because raising it later can require a data migration.
  • Transaction behavior: Inline payloads commit with the rest of the write, which simplifies consistency for small attachments.

Before relying on the default, sample your real Binary sizes and check what share of them falls under the threshold.

Configuration options and when each fits

This table compares the database default with FILESYSTEM binary storage, the inline size threshold, and the writable directory the server process needs. Read each row as a decision: what the option does, when it fits a deployment, and what changes for backups, restores and reads. The main takeaway is that filesystem storage moves large payloads out of the database, so the database backup alone no longer captures every document.

OptionWhen it fitsWhat changes for backups, restores and reads
binary_storage_mode set to databaseSmall Binary payloads, or deployments that want every resource and its content in one database backupBinary content lives in the database, so a single database backup and restore covers it; large documents increase database size and backup time
binary_storage_mode set to FILESYSTEMLarge documents and images that would make the database heavy to store, back up and restorePayloads are streamed to disk, so backups must cover both the database and the binary directory and keep them in step
inline_resource_storage_below_size omitted (default 102400 bytes)Most payloads are small and you want the 100 KB default threshold to decide where content landsPayloads under 102400 bytes stay in the database even when filesystem mode is on, so reads of small content still come from the database
inline_resource_storage_below_size set lower or higherYour payload profile is clearly skewed, for example many mid-sized scans or very few large filesMoving the threshold changes which content sits in each store, so confirm the split before you change it on a populated server
Directory writable by the server processAny FILESYSTEM deployment, on a path the application server user can write to and read fromPermissions govern reads as well as writes; restores must recreate the directory with the same ownership, or reads of stored binaries will fail
Directory on shared or network storageMulti-instance deployments that need every replica to read the same filesConfirm locking, latency and mount behavior with your storage team, and include the mount in restore and failover runbooks

How to configure filesystem Binary storage in the starter

This sequence takes a HAPI FHIR JPA starter from database-only Binary storage to a configuration where larger Binary payloads are written to a directory on disk, with a tested upload and read that confirms the setup works. Each step ends with a check so the team knows it is complete before moving on.

  1. Choose the starter deployment method

    Decide how the hapi-fhir-jpaserver-starter will run in your environment, such as the hapiproject/hapi Docker image, Docker Compose, Spring Boot, a WAR on Tomcat, Jetty or Wildfly, or Kubernetes with the Helm chart. The chosen method determines where configuration is set and where the storage directory must be mounted, so the platform team should settle it first. Confirm that the deployment method and version you pick match the configuration keys in the starter README for that version. Done when the team has a written record of the method, the starter version and the environment that will host it.

  2. Set binary storage mode to filesystem

    Set the starter configuration key binary_storage_mode to FILESYSTEM, using the mechanism your chosen deployment method uses for configuration, such as environment variables, a properties file or Helm values. The platform engineer making this change should record it in version control so it is reviewed like any other config change. Confirm the exact key name and value against the starter README for your version before deploying. Done when the running server reads the setting on startup and the change appears in the deployed configuration.

  3. Decide the inline size threshold

    Decide whether to set inline_resource_storage_below_size or leave it unset. If it is omitted, Binary payloads under 102400 bytes (100 KB) stay in the database and larger payloads stream to disk. Set a different value only after the team has reviewed the typical size of documents and images it expects to store, since a lower threshold moves more payloads to the filesystem and a higher one keeps more in the database. Record the chosen value and the reason for it. Done when the threshold decision is documented and the configuration matches it.

  4. Create the storage directory

    Create the directory that will hold the Binary files on the host or volume the server uses, and mount it into the container or pod if the server runs in one. Keep the directory on storage that your backup process covers, and place it outside the application code directory. Confirm the path matches the value your configuration expects. Done when the directory exists on the target host or volume and the path is recorded in the deployment documentation.

  5. Grant write permission to the server process

    Give the operating system user that runs the HAPI FHIR process write access to the storage directory, and no broader access than it needs. In containers, confirm the user ID inside the container has permission on the mounted volume, since host and container IDs often differ. Check that other local users cannot read the directory by default. Test by running a write as the server user, such as creating and deleting a temporary file, and confirm it succeeds. Done when the write test passes under the service account and a read test from an unrelated account is denied.

  6. Start the server and confirm the configuration loaded

    Start or restart the HAPI FHIR server and review the startup logs for errors about the storage directory or the binary storage setting. Confirm the server responds on its metadata endpoint, which shows it is running with the new configuration. If startup fails on the directory, check ownership and mount paths before changing any other setting. Done when the server starts cleanly and the logs show no storage-related errors.

  7. Test with a Binary upload and read

    Create a Binary resource through the server with a payload above your inline threshold, then read it back and compare the returned bytes with the original file. Then confirm a file was written to the storage directory and that a payload below the threshold stays in the database. Run the same test on a non-production copy before production, and keep the test file and results for the change record. Done when the large payload round-trips intact, a file appears in the directory, and the small payload behaves as the threshold predicts.

  8. Document the final configuration and confirm with the starter README

    Write down the final values for the storage mode, threshold, directory path, service account and mount points, and attach the starter version used. Ask the team that owns the starter upgrade path to re-check these keys against the README whenever the starter version changes. Include the backup and permission requirements in the same record so operators see them together. Done when the configuration record is stored with the deployment runbook and has a named owner.

How the database and disk split a Binary resource

When the HAPI FHIR JPA starter stores a Binary resource with binary_storage_mode set to FILESYSTEM, the server makes a size decision on every write. Payloads below the inline_resource_storage_below_size threshold are kept in the database as they would be without filesystem storage. Larger payloads are streamed to a directory on disk, and the database keeps only a reference to that file. The default threshold is 102400 bytes (100 KB) when the key is omitted, so the threshold is the first setting to review, because it decides how many documents and images leave the database at all. On read, the server uses the stored reference to fetch the file from disk and returns it to the client as the same Binary resource, so clients see no difference.

The database still holds the Binary resource row, its metadata, its version history and the pointer to each file, so the database and the disk are two halves of one record. A database restore without the matching files produces Binary resources that exist but cannot be read. A file restore without the matching database rows leaves orphaned files that no resource references. Your backup design must therefore capture both at the same point in time, or at least restore them to a consistent state, and your recovery test should read a sample of large Binary resources after restoring both. Confirm with your DBA and platform team how the database snapshot and the file copy will be taken together, since the starter documentation does not define that procedure for you.

The process running the server must be able to write to the configured directory and read from it, so file ownership, mount options and container volume settings need to be planned with the deployment, not left to the first failed upload. Confirm how the directory will be shared across replicas if you run more than one server instance, since a file written by one instance must be readable by the others. Plan the directory on storage with the capacity, encryption and access controls your data classification requires, and check the HAPI FHIR JPA starter documentation for the current settings before you fix the layout.

How a Binary write is routed to the database or disk

A Binary write enters the HAPI FHIR JPA starter, which compares the payload size with the inline_resource_storage_below_size threshold. Payloads under the threshold stay in the relational database, while larger payloads are streamed to the directory set for binary_storage_mode FILESYSTEM. Check that the directory is writable by the server process and that backup jobs cover both the database and that directory, since either path alone leaves part of the data unprotected.

Routing of a Binary write between the database and the filesystem directory.

Permissions, access and audit for files on disk

A filesystem binary store moves payload bytes outside the database, so the directory becomes a second place where patient documents live. The cards below cover who can write and read those files, how API reads are governed, and what audit evidence you can produce.

Directory ownership and write access

The directory named in the starter configuration must be writable by the user running the HAPI FHIR process, so that user is the one that can create, overwrite or delete stored payloads. Confirm the owning account, the group and the mode bits on the directory, and confirm that no other service account, backup job or administrator shares write access. Record the path and owner in your configuration baseline so a later change is visible.

Starter README

Restricting direct filesystem access

Operating system permissions should keep interactive users, batch jobs and unrelated containers away from the binary directory. In containerized or Kubernetes deployments, confirm which volume mounts expose the path, whether the mount is read-only for any pod that does not need writes, and which nodes can reach the underlying storage. Test that a shell session under a different account cannot list or open a stored file.

API reads govern file access

Filesystem permissions do not decide who receives a Binary through the FHIR API. Reads go through the server, so access control has to be enforced there using the server's authorization building blocks, since HAPI FHIR does not supply a single security layer. Model a test where a user without rights to a patient's compartment requests the Binary by its logical ID, and confirm the request is refused before any file is opened.

HAPI FHIR security docs

Interceptor-based authorization checks

Because authorization is assembled from interceptors such as the AuthorizationInterceptor, each rule that covers a Binary resource must be written and tested explicitly. Confirm that rules cover create, read, update, delete and search paths for Binary, and that search results cannot reveal Binary metadata for records the caller may not see. Review interceptor order and version changes during upgrades, since a rule that silently stops matching leaves files exposed.

Audit logging with BALP

BALP audit logging is one of the building blocks HAPI FHIR documents for recording access to resources. Confirm that it records Binary reads and writes with the caller identity and the resource reference, and that the log destination is protected from the same account that writes the files. Verify with a test read that an entry appears, because audit coverage for payload downloads is a claim to confirm in your version rather than assume.

Orphaned and unlogged file changes

A file changed directly on disk bypasses the API, the interceptors and any audit entry, and a deleted database row can leave a payload behind. Plan a periodic reconciliation between database references and directory contents, and restrict who can perform manual cleanup. Document the procedure as a change under your access review so that every removal of patient content has an owner and a record.

Questions teams ask before storing Binary files on disk

Does storing Binary files on the filesystem reduce database size?

Yes, for the payloads that cross the threshold. With binary_storage_mode set to FILESYSTEM, the starter streams large Binary payloads to disk, so the database keeps the resource row and metadata instead of the full file content. Payloads under the inline threshold still stay in the database unless you change inline_resource_storage_below_size. The database saving depends on how much of your Binary volume is large documents and images versus small attachments. Cost moves rather than disappears: disk capacity, backup storage and the work to keep the two stores consistent become your costs. Ask your team to measure the current Binary share of the database before estimating savings.

How long does a migration to filesystem storage take?

Duration depends on how much Binary content already sits in the database, how it is read and rewritten, and whether the service must stay up during the move. The starter's documented setting governs new storage behavior, so existing payloads need a planned rewrite or a controlled cutover, and that work scales with data volume and I/O capacity. Before committing to a window, confirm the volume and size distribution of existing Binary resources, the available disk throughput, and whether a maintenance period is acceptable. A written scope should state the test cycle and rollback approach before any production run.

Can our own team set up filesystem Binary storage without a partner?

Yes, if your team already runs HAPI FHIR JPA server deployments and can manage the storage side. The configuration itself is small: enable FILESYSTEM mode, set the threshold, and make sure the process can write to the directory. The harder parts are outside the config file:

  • Sizing and provisioning the volume, including growth over time
  • Coordinating backups and restore tests across the database and the directory
  • Setting file permissions, ownership and container volume mounts
  • Planning migration of existing data and verifying it

A partner is useful when the team lacks capacity or wants the work fixed in a written scope with a retest.

What changes for backups when Binary files live on disk?

You must back up two stores that must stay consistent: the relational database and the Binary directory. A database dump alone will miss every file stored on disk, and a file copy alone will miss the metadata that points to it. Plan a backup procedure that captures both at matching points, and test restores by rebuilding a server from both and checking that sample Binary resources download correctly. Ask whether your backup tool supports snapshots across the volume and database, how retention applies to the directory, and how long a full restore takes. Encryption and off-site copies must cover the directory too.

How are deletes handled for files stored on disk?

Deleting a resource through the API does not, by itself, guarantee that the matching file is removed from disk on every path, so verify this behavior in your version before relying on it. Retention and erasure requests need a documented procedure that covers the database row, the file, and every backup copy. Ask your engineers to test delete and expunge operations in a staging environment and confirm whether orphaned files are left behind. Build a periodic reconciliation check that compares database references with files on disk.

How should access control apply to the Binary directory?

Treat the directory as sensitive patient data. The FHIR server's authorization decides who can read a Binary resource through the API, but anyone with operating system access to the directory can read the files directly, so restrict that path. Set the directory owner to the service account, limit group and other permissions, keep it off public web roots, and mount it read-write only into the server container. Review who holds shell or volume access, and log administrative access where your platform allows it. Confirm these controls with your security team against the server's authorization setup.

Does the directory need to be writable by the server process?

Yes. The directory must be writable by the process that runs the server, or uploads of large payloads will fail. Check ownership and permissions for the user that runs the container or application server, including after volume remounts and in Kubernetes security contexts. Confirm the path and free capacity in your monitoring so write failures surface before users see them.

How DeployOpen works on this

DeployOpen plans and implements filesystem-backed Binary storage for a HAPI FHIR JPA server inside your own infrastructure. The work covers the storage directory, the inline size threshold, process permissions, backups and handover, so your compliance and operations teams can review each control.

How we scope

  • Inventory which Binary payloads, such as documents and images, your server stores and their typical sizes
  • Agree the storage location, mount type and the inline threshold in a written, fixed-scope plan
  • Confirm the server platform, starter version and database so the storage design matches your environment
  • Define backup, retention and access expectations for the file directory before any configuration changes

How we build

  • Configure binary_storage_mode as FILESYSTEM and set inline_resource_storage_below_size deliberately, not left at its default
  • Make the storage directory writable by the server process only, with ownership and permissions documented
  • Test uploads and reads of payloads both below and above the threshold, confirming where each one lands
  • Verify that database and file store stay consistent after restarts and failed writes in a non-production copy

How we hand over

  • Deliver the configuration, directory layout and permission model as written documentation for your team
  • Provide a backup runbook that pairs database dumps with file directory snapshots taken at the same point
  • Document the restore test steps and the evidence your auditors or security reviewers are likely to request
  • Walk your operations staff through monitoring disk capacity and the procedure for moving the directory

How we support

  • Retest storage behavior after HAPI FHIR and starter upgrades, since configuration keys can change between releases
  • Support ongoing operations, patching and capacity reviews through a retainer if your team wants continued help
  • Run a periodic restore exercise and review of directory permissions as part of a retainer engagement
  • Confirm any changes to threshold or storage location through a documented change before they reach production

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.