HAPI FHIR batch jobs: reindexing, export and expunge at scale

Batch2 jobs let a HAPI FHIR JPA server reindex, export and expunge large volumes without blocking clients. This page covers how they run, recover, scale across instances and get scheduled.

On this page

Why HAPI FHIR batch jobs decide whether a large server stays usable

On a large HAPI FHIR JPA server, batch jobs often decide whether clients keep getting fast responses. Reindexing, bulk export and expunge each read or rewrite large parts of the database, and they run against the same database and JVM that serve your applications' reads and writes. The HAPI FHIR JPA Server stores FHIR data in a relational database through the JPA API, so every job draws on the same connections, storage I/O and memory that searches and transactions depend on. A job started during business hours can slow the clinical applications that share the server, even when the job itself completes correctly. Teams should treat batch work as capacity they must schedule and measure.

The batch2 framework is the job system HAPI FHIR uses for these long operations, so each job is tracked while it runs. Confirm in the documentation for your release how jobs are divided, how their state is recorded and how a job resumes or fails after a node restarts mid-run, because that recovery behavior is what your operators will depend on during an incident. Job names, parameters and defaults can change between releases, so check the exact definitions for your version before you write any scheduling or monitoring automation. The HAPI FHIR versions page is the place to start that check.

Start the plan with the version and platform. HAPI FHIR 8.2.0 requires JDK 17, and v8.8.2 was released on 25 September 2026, so confirm which release and Java runtime your server uses before you test batch behavior. For production, the JPA server starter supports PostgreSQL and Microsoft SQL Server and does not support MySQL, so the database that absorbs batch load must be sized for it. Before go-live, rehearse each heavy job on a copy of production-sized data, record its duration and its effect on read latency, and agree with clinical and integration owners which windows allow it. Those measurements, more than the job list, should set the schedule.

A batch2 job is stored in the database, then picked up and chunked by any instance

The job starts with a request to one HAPI FHIR instance, which saves the job instance and its work chunks in the database job tables. Worker instances on the same database claim chunks, process them and write results back, so status queries from any instance show progress. When a step fails, it is retried or resumed from its last saved state rather than restarted from the beginning. Check that every instance points at the same database and that a failed chunk shows a retry count in the job tables.

Jobs and chunks live in the database, so any instance can run or report them.

How batch2 jobs run, checkpoint and recover after failure

A batch2 job in HAPI FHIR is split into a job instance that represents the whole request, such as a reindex or bulk export, and a set of work chunks that each cover a slice of the work. Work chunks are stored in the database, and worker threads on each server pick them up, process them and mark them complete. Because state lives in the database rather than in JVM memory, the job's progress survives a restart of the process that was running it. Confirm the exact job definitions, chunk sizes and status values in the HAPI FHIR documentation for the version you run, since the internal tables and job names have changed between releases.

Recovery depends on the chunk state, not on the job as a whole. When an instance stops mid-job, chunks it had claimed but not finished are left in an in-progress state, and a maintenance task on another or restarted instance is expected to detect stale work and return those chunks to the queue. Work is therefore designed to be repeatable, and a chunk may run more than once. Before you rely on this, read the recovery and stale-chunk settings in the documentation for your version and test a forced kill during a reindex in a non-production copy. Check that the job finishes, that no chunk is stuck in progress, and that resource counts match what you expected.

After any crash, check three things: the job instance status, the count of chunks by state, and the server logs from the instance that failed. A job that shows no movement for longer than your normal chunk duration needs investigation before you restart anything. Keep a runbook entry that records who may cancel a job, how a cancelled job is resubmitted, and how you confirm that the search index is complete afterward. These steps are part of the operating model you need to agree with your DBA and platform team before the first production run.

Batch job options and when each fits

This table compares reindexing, export and expunge jobs on a HAPI FHIR JPA server by scope, chunk handling, cross-instance concurrency and maintenance window fit. Read each row as a question to answer for your repository before scheduling anything. The main takeaway is that every job trades database load against runtime, so the safe window depends on your own measurements, not on a generic rule.

Job or settingWhat it does to the databaseConfiguration choicesWhen it fits a large repository
Reindexing (scoped by resource type)Reads resources in chunks and rewrites search index rows, which adds sustained read and write load on the primary databaseNarrow the scope to the resource types or search parameters that changed; confirm chunk size and thread settings against your database capacityUse after a search parameter change or index repair, and schedule it in a window where you have measured the load
Reindexing (full repository)Touches every stored resource, so load and runtime grow with repository size and can run for a long timeFull scope, with concurrency limited so application traffic keeps its share of database connectionsPlan for a maintenance window and rehearse on a copy of production data before any full run
Export (bulk data export)Reads resources across the repository and writes output files, mainly adding read load and temporary storage useSelect resource types and date ranges to limit scope; confirm where output files are written and how long they are keptFits scheduled extracts to downstream consumers, often outside peak hours, when the output location has enough space
ExpungePermanently deletes data and its index and history rows, creating heavy write and delete activityConfirm the scope carefully, including whether history and related resources are removed; keep a verified backup before runningFits removing data that must be purged under retention or policy, run as a planned, reviewed change in a maintenance window
Chunk sizeLarger chunks reduce per-chunk overhead but hold more rows and locks at onceConfirm the default and tune only after measuring database wait times and job progressLower values suit shared databases; higher values suit a dedicated database in a quiet window
Concurrency across instancesMore instances processing chunks raise parallel database load quicklyConfirm how work is divided between instances and how many run in parallel for each job typeUse several instances for long jobs only when the database has spare connections and capacity
Maintenance windowMoves heavy load away from clinical or application peaks but does not reduce total workSet the window from measured peak hours and job duration in a test run, not from assumptionsRequired for full reindexing and expunge; optional for small scoped exports that run at low load

Running batch jobs across several instances safely

Batch2 jobs keep their state in the shared database, so every instance that can see that database can also pick up, duplicate or interrupt work. The six considerations below decide whether reindexing, export and expunge jobs finish cleanly when more than one HAPI FHIR JPA server is running.

Which instances run jobs

Not every node in a cluster should execute batch work. Decide which instances are allowed to run batch2 job steps, and confirm the configuration on each node rather than assuming defaults match across the fleet. A reindex or expunge started from an instance that was never sized for heavy writes can compete with live clinical traffic. Document the eligible nodes, and check that each one has the same configuration for database access and job processing.

Shared database job state

Batch2 records job instances and their steps in the database, so every node reads the same progress. Treat that job store as critical state: include it in database backups, watch its growth, and confirm that every instance points at the same schema. A node pointed at a different or stale database will report progress that does not match reality. Ask your team to verify job records after any failover or schema change.

Avoiding duplicate work

Two instances must not process the same chunk of a reindex or export. Confirm how your HAPI FHIR version claims work units and whether the claim is protected against two nodes picking up the same step at once. Duplicate expunge work is wasteful, and duplicate export writes can produce inconsistent output files. Test the claim behavior with a small job on your target version before running a large one.

Instance restarts during a run

Rolling restarts, autoscaling events and node failures will interrupt jobs. Find out which steps resume from the last completed chunk and which must restart from the beginning, and how long a stalled step waits before another node takes it over. Plan maintenance windows so that deployments do not stop a long reindex halfway. Record the restart behavior you observe in a test environment as part of your runbook.

Sizing worker threads

Each batch node uses its own worker threads, and each thread holds database connections while it processes a chunk. Total thread count across all eligible instances, multiplied by connections per thread, must fit within what the database can serve alongside live traffic. Start with conservative settings, measure database CPU, lock waits and connection pool saturation, and increase only when the numbers allow it. Ask your vendor or partner for the thread and pool settings they used in any sizing test.

Separating client and batch nodes

Routing client searches and writes to the same nodes that run reindexing invites contention on CPU, memory and the connection pool. Many teams place batch execution on dedicated instances behind a separate internal route, while client traffic goes through the public load balancer. Confirm that the load balancer excludes batch-only nodes from client routing, and that health checks reflect the state you want. Review this split whenever you add instances or change the job schedule.

JPA server docs

How to set up and schedule heavy jobs away from peak hours

This sequence takes a heavy HAPI FHIR batch job from version and database checks through a tested run on a copy of production data, a scheduled window, and verified results. Each step ends with a check so the team knows the job is safe to schedule.

  1. Confirm version and database settings

    Start by confirming the HAPI FHIR version and the JDK it requires. The HAPI FHIR versions documentation states that 8.2.0 requires JDK 17, so check the release you run against that page before changing anything. Then confirm the database behind the JPA server is PostgreSQL or Microsoft SQL Server, since the starter does not support MySQL, and record the connection pool and storage settings your operators will need when they watch the job. Done when the version, JDK, database and pool settings are written down in a change record that the database and platform owners have reviewed.

  2. Enable batch processing on chosen instances

    Decide which server instances will run batch2 jobs and which will only serve requests, then set the batch processing configuration on the chosen instances only. Keep the change in version control so every instance can be checked against the same file. Confirm that each enabled instance starts cleanly and that the job framework is reachable from it. Done when a configuration diff between the instances matches the plan and each chosen node reports a healthy startup in its logs.

  3. Test a job on a copy of production data

    Restore a recent copy of the production database into a non-production environment with matching instance sizing, then run the job you plan to schedule, such as reindexing or a bulk export. Record start time, end time, error count and how the job behaves if one instance is stopped mid-run. Ask the database team to capture load and lock activity during the run. Done when the test run completes, the job status ends in a completed state, and the recorded load numbers are reviewed against the production window you intend to use.

  4. Define the schedule and the maintenance window

    Using the test results, choose a window when read and write traffic is lowest, and agree it with the application owners and the on-call rota. Document who can start, pause and cancel a job, and what the fallback is if the window closes before the job finishes. Set the schedule in the tool your platform team uses, such as a cron job or a workflow scheduler, and avoid overlapping heavy jobs. Done when the schedule, owners and cancel procedure are signed off and a dry run confirms the trigger fires at the agreed time.

  5. Monitor progress during the run

    During the scheduled run, watch the job status through the server's batch job reporting and the database's own views for active sessions, waits and locks. Compare the rate of progress with the test run and note any stall, repeated error or growth in lock waits. Confirm that API response times for clinical users stay within the limits your team set before the run. Done when the job reports completion, or when the team has made a documented decision to pause or cancel and has confirmed the system is back in its normal state.

  6. Verify results and close the change

    After the job finishes, check that its output matches what was requested. For reindexing, run a sample of searches that depend on the rebuilt indexes and compare results with the pre-run baseline. For export, confirm the file count and that the output passes the checks your recipient expects. For expunge, confirm the targeted data is gone and that the audit trail records the operation. Done when the sampled checks pass, the results are recorded in the change record and the schedule is either kept for future runs or removed.

Monitoring job progress and spotting stalled work

Operators own the question of whether a job is still moving. Start from the status location returned when the job was submitted, and record the job identifier in the change record so anyone on shift can find it. Read the status as a sequence of states rather than a single yes or no, and compare progress against the window agreed before the run.

  • Record the identifier at submission: Store the job identifier and status location in the change ticket so handover does not depend on one person's terminal history.
  • Read the state and the last change together: A job can report a running state while producing no new output, so check completion counts alongside the time of the most recent change.
  • Compare against a baseline: Keep throughput figures from a test run on a copy of the data, and flag any run that falls well outside them.
  • Check how many instances are working: Confirm how many instances are picking up work. A job running on one node when you planned for several will look slow for reasons unrelated to the data.
  • Confirm what the endpoint reports: Check your version's documentation for the status fields and metrics it exposes before relying on them.

Before the run starts, confirm which status fields your version exposes and agree who is paged if progress stops for longer than the planned window.

Security and operational risks of expunge and bulk export

Batch jobs on a HAPI FHIR JPA server touch the most sensitive data in the system, often in bulk and often without a second pair of eyes. HAPI FHIR supplies building blocks for authorization and audit, but the operator must add the controls around expunge, export files and job endpoints.

Expunge is irreversible

Expunge permanently removes resource data from the database, and it cannot be undone from within the server. Before any expunge runs, confirm a verified database backup exists, record the exact resource selection and the reason for it, and run it first against a restored copy. Restrict who can start it through the authorization layer you build, and require a second approver for anything beyond a single resource type. Confirm with your own tests how your version handles expunge of versioned history and referenced resources.

HAPI FHIR security docs

Expunge authorization controls

Expunge should not be reachable by the same credentials that serve clinical reads and writes. Map the operation to a dedicated role in your identity provider, and enforce that role with an authorization interceptor so that a valid token alone is not enough. Log who requested the job, when, and against which partition, so the audit trail answers the question an auditor will ask first. Confirm how your chosen authorization approach evaluates batch operations, since these are not ordinary resource requests.

Export files carry full patient data

A bulk export writes resource content for every selected patient to files outside the database, so the export location is a data store in its own right. Write output only to an encrypted location with restricted read access, and set a retention period that deletes files once the consumer has collected them. Treat the file share, object bucket or volume as in scope for your privacy and security assessments. Confirm where your deployment writes export output and who can list or download it.

Download access to exports

Export results are usually fetched over HTTP through a URL that the job returns, so anyone holding that URL can read the file. Limit the download endpoint to the requesting client, avoid sharing links through ticketing or chat tools, and keep the URL lifetime short where your setup allows it. Pair these controls with an audit record of each download. Confirm how long the generated links remain valid in your version before you publish any export procedure.

Job endpoints need restriction

The endpoints that start, cancel, or read the status of batch jobs are operational interfaces, not FHIR resources, and they are easy to overlook in a gateway configuration. Place them behind network controls and the same authentication as admin tooling, and do not expose them through a public ingress path. Review reverse proxy rules after each deployment change, since a route that works for clinical traffic can also pass job requests. Confirm the full list of job-related paths for your version before writing firewall rules.

Backups and recovery planning

Batch jobs change large volumes of data in one run, so recovery depends on a restore path you have tested before the job begins. Take a backup immediately before reindexing, export or expunge, and record the backup identifier in the job runbook. Verify that a restore brings back the data and the search indexes, not only the resource tables. Ask your database team to confirm restore time for the size of your largest data set, since that number decides whether a failed job can be rolled back during business hours.

Questions teams ask before running batch jobs on a large HAPI FHIR server

What drives the cost of planning batch jobs on a HAPI FHIR server?

The main cost drivers are the number of resources and search index rows the job touches, the size and performance of the database, the number of server instances involved, and how many environments need a rehearsal first. Your own staff time is one cost, and a fixed-scope partner engagement is another. Planning, runbooks and rehearsal runs are one-time costs. Reindexing after an upgrade or a search parameter change, and scheduled expunge runs, recur. Database compute and storage used during each run also add cost. Ask any quote to list which jobs are covered, which environments are tested, how many rehearsal runs are included, and who watches the live run.

How long does a batch job take on a large HAPI FHIR server?

No reliable duration can be given without measuring your own data. Run time depends on the resource count, the number of index rows that must be rebuilt, database I/O, JVM and thread settings, concurrent traffic from clients, and how many instances share the work. The most dependable estimate comes from a rehearsal on a copy of production-sized data, timed on the same hardware and database settings you will use. Record throughput over the first minutes of the run, then project it across the full dataset. Confirm the expected behavior for your HAPI FHIR version in the official documentation before you set any maintenance window.

What does a batch job need from our internal team?

A batch job needs four groups of people. A database administrator must confirm backups, storage headroom and the database settings the job depends on. A platform engineer must manage the server instances, the Java runtime and any changes to the deployment. A named owner must decide when the job runs, who approves a start, and when to stop it. Someone must watch job status and logs during the run and act on alerts. For recent releases, the Java requirement can change, so check the JDK version for your target release. For version 8.2.0, for example, the documentation states JDK 17 is required.

Can our team run HAPI FHIR reindexing and export jobs ourselves?

Yes, if the team has the skills and time to operate the job end to end. The work is mostly operational: it needs Java and server administration, database expertise, monitoring, and a tested rollback path. Decide based on whether you have that skill set, whether you can cover the run outside business hours, and whether you can rehearse on production-sized data before the real run. Teams that cannot cover those points often choose a fixed-scope engagement from DeployOpen, which plans, runs and documents the work in your own infrastructure. Either way, agree the runbook and ownership in writing before the first live run.

How do we schedule heavy batch jobs away from peak hours?

Start with traffic data from your monitoring stack. Find the hours with the lowest read and write volume across all time zones your users work in, then set the window from that pattern rather than from assumptions. Build in a stop point so the team can halt a job if clients see slow responses. Check whether your deployment can run jobs on a separate instance so client traffic stays on the others. If you use partitioning, confirm with the HAPI FHIR partitioning documentation how partitions affect where and how work runs before you rely on it for isolation.

What happens if a batch job fails halfway through?

The first step is to stop further changes, read the job status and server logs, and identify the cause before you restart anything. Whether a failed job can resume, or must be run again from the beginning, depends on the job type and the HAPI FHIR version, so confirm that behavior in the documentation for your release. Take a database backup before any job that deletes data, because expunge is destructive. Once the cause is fixed, rerun the job in a rehearsal environment first, then in production. Record each failure and its fix in the runbook so the next run starts with that knowledge.

Which security controls matter when running export jobs?

Export output usually contains personal health data, so the controls around who can start a job and who can read its output matter as much as the job itself. Restrict job start and status endpoints to a small set of administrators through authorization. Store export files in a location with access limits, encryption at rest and a defined retention period. Keep audit records of who started each job and who downloaded its output. HAPI FHIR provides building blocks for this, but it does not supply a complete security layer, so you must design and test the controls around it. Review the HAPI FHIR security introduction before you design the access model.

How DeployOpen scopes and runs HAPI FHIR batch job work

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own infrastructure, including HAPI FHIR JPA servers. For batch jobs, we start from your data volumes, operating windows and recovery expectations, then build the scheduling, monitoring and runbooks around the server you run.

How we scope

  • Inventory which batch jobs you expect to run, such as reindexing, export and expunge, and how often each runs.
  • Agree the database, JVM and instance layout the jobs will share with live FHIR traffic.
  • Confirm peak-hour windows, change approval rules and who may start or cancel jobs in production.

How we build

  • Configure the HAPI FHIR JPA server and batch2 job settings for your deployment and Java version.
  • Test job restart and recovery on a staging copy of your data before any production run.
  • Build dashboards and alerts that report job progress, failures and database load during each run.

How we hand over

  • Document the job runbook: start, pause, resume, cancel and verification steps, written for your operators.
  • Deliver scheduling configuration, monitoring setup and a recovery checklist stored in your own repositories.
  • Walk your platform and database teams through the handover and record open questions for follow-up.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing upgrades, job reviews and continuous testing are available as a retainer after handover.
  • Ask us to confirm version-specific batch job behavior against the release you run before each upgrade.

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.