Why Medplum bulk loads slow down and how a migration team plans around it
The main risk in a large load into a self-hosted Medplum server before cutover is GIN index contention, and the cutover window is set by tuning those indexes and then measuring real throughput. On Medplum's search indexes, the default fastupdate behavior can cause bulk imports and high-concurrency upserts to produce serialization errors (40001), slow queries and write latency spikes. The migration team should treat these symptoms as a planning input, not as an incident to handle after the load starts.
The effort depends on three things the team must measure in its own environment: dataset size, the number of concurrent loaders, and whether the Medplum server and its PostgreSQL database are shared with live traffic. A load into an idle staging server tells the team little about a load that runs while clinicians or integrations are writing to the same tables. Confirm the expected resource counts per type, the load concurrency your loaders will use, and whether any read or write traffic will continue during the window, then run a representative test against a copy of production-scale data.
Self-hosted super admins can disable fastupdate per table with the asynchronous $db-configure-indexes operation, which also runs VACUUM. Medplum recommends transactionAttempts of 3 to 4 and a 200 ms backoff base delay as a complementary measure for retries. Plan these as configuration changes with a named owner, and record which settings were in force for each measured run so the throughput numbers are repeatable. Ask Medplum or your DeployOpen contact to confirm the exact procedure for your Medplum version before you run it, since the operation is an administrative action with effects on a live database. The Medplum GIN index performance guide sets out the operation and its settings.
Choosing between fastupdate changes, retry settings and load pacing
Disabling GIN fastupdate on a table is the most direct fix when the GIN index on a busy table is the source of serialization errors, slow queries or write latency spikes during a bulk import. Medplum uses PostgreSQL GIN indexes for search, and with the default fastupdate setting, bulk imports and high-concurrency upserts can produce serialization errors (40001) and latency spikes. The change is made per table with the asynchronous $db-configure-indexes operation, which also runs VACUUM. Only self-hosted super admins can run it, so the platform team must confirm that the people who will execute the change hold that role on the server.
- Scope: The setting applies per table, so start with the tables your loader actually writes to heavily rather than changing every table.
- Who runs it: Super admin rights on the self-hosted server are required. Medplum Cloud customers cannot make this change themselves.
- Trade-off: Without fastupdate, individual index writes cost more, so ordinary inserts can run slower while the setting is in place.
- Timing: Plan the VACUUM work as part of the change, and confirm with your database team how long it will hold resources on your PostgreSQL instance.
- Reversal: Confirm how to restore the previous setting after the import, and record the table-level state in your cutover runbook.
Before changing anything, measure the import on a non-production copy to confirm that the GIN index is the cause, and check the Medplum GIN index performance guide for the current procedure.
Retry settings are a complementary measure. They do not remove the cause of serialization conflicts, but they let transactions that fail with a serialization error (40001) complete on a later attempt instead of failing the batch. Medplum recommends a transactionAttempts value of 3 to 4 with a 200 ms backoff base delay. Because these settings sit in the server configuration, changing them normally requires the same self-hosted operator access as any other server change, and the server must be restarted to apply them.
- Recommended values: Start with transactionAttempts between 3 and 4 and a backoff base delay of 200 ms, as Medplum recommends.
- What it fixes: Transient conflicts between concurrent writers, where a retry is likely to succeed.
- What it does not fix: Sustained contention or a GIN index that is slowing every write. Retries under those conditions add load and extend the run.
- Trade-off: More attempts mean a failing transaction can take longer to surface as an error, so loaders must still log and track final failures.
- Interaction with loader design: Confirm that your loader is idempotent, because a retried write must not create duplicate resources.
Record the retry values used in each rehearsal, so that throughput measurements can be compared like for like.
Reducing loader concurrency lowers the write pressure your import places on the database, and it requires no database administration rights. It is the lever the loader team controls directly, and it is often the first step while the platform team prepares the fastupdate change. The trade-off is time: fewer parallel writers lengthen the import, so the cutover plan must absorb a slower run. Concurrency is a pacing decision, not a configuration change on the Medplum server.
- Who controls it: The migration engineers who own the loader, without needing super admin rights.
- What it fixes: Write latency spikes and contention caused by too many parallel batches or transactions.
- Trade-off: Throughput falls in proportion to the reduced parallelism, so the run takes longer and the cutover window must reflect it.
- Measurement: Test several concurrency levels in a rehearsal and record throughput and error counts at each level.
- Combining levers: Pacing can be used alone, with retries, or alongside a fastupdate change, depending on what the rehearsal shows.
Check whether a reduced run still fits the agreed window with the people who own the cutover, and confirm the figures against your own rehearsal results rather than assumptions.
The three levers differ in who must act and who must agree. The fastupdate change needs super admin rights on the self-hosted server and the involvement of database administrators, because it runs VACUUM and alters index behavior on production data. Retry settings and loader pacing sit with the platform and migration teams. Because the Medplum server is self-hosted in your infrastructure, your organization carries the operational responsibility for every change, and Medplum Cloud does not offer the same control.
- Super admin holders: Name the individuals who can run
$db-configure-indexesand confirm their access before the rehearsal. - Change approval: Route the fastupdate change through your normal change process, with a rollback step recorded.
- Database team: Involve the team that owns PostgreSQL so that VACUUM timing and resource use are agreed in advance.
- Audit trail: Keep a record of every configuration change made during the import, which supports later compliance review.
- Hosted deployments: If you run on Medplum Cloud, these server-side levers are not available to you, so ask Medplum which options apply to your plan.
Confirm these roles and approvals in writing before the cutover plan is finalized.
Sequence for tuning and measuring a bulk load before cutover
This sequence establishes a measured throughput baseline, applies GIN index tuning only where the evidence points to it, and records verified results in the cutover plan. Each step closes with an output the team can check before moving on.
Confirm the self-hosted version and upgrade path
The migration team and the platform owner confirm the exact Medplum server version running in the dress-rehearsal environment and compare it with the target production version. Self-hosted Medplum must be upgraded through each minor version in sequence, so any gap in the path is resolved before tuning starts, because results from one version do not carry over to another. The step is done when both versions are written down, the upgrade path between them is documented, and any pending post-deploy data migrations are known to the team.
Baseline throughput on a dress-rehearsal dataset
The team runs the existing loader against a copy of the production-scale dataset in a non-production environment that matches production sizing for PostgreSQL, Redis and the Medplum server. They record resources per second, error counts, serialization errors (40001) and write latency for each resource type, with no GIN tuning applied yet. The output is a baseline table that shows where time and errors concentrate, which becomes the reference for every later comparison. Confirm that the dataset is representative by checking resource counts and reference patterns against the source extract, not by assuming it.
Identify busy GIN-indexed tables
Using the baseline run and database statistics, the DBA or platform engineer lists the tables that receive the heaviest insert and update volume and that carry GIN indexes used for search. Medplum uses PostgreSQL GIN indexes for search, and the default fastupdate behavior is the suspected source when bulk imports and high-concurrency upserts show serialization errors, slow queries or latency spikes. The step is done when a short list of candidate tables is linked to specific errors or slow statements in the baseline, so that no table is changed without evidence.
Run the index configuration operation asynchronously with VACUUM
A self-hosted super admin disables fastupdate on the candidate tables by running the asynchronous $db-configure-indexes operation, which also runs VACUUM. The operation is run on the dress-rehearsal environment first, and the team monitors its progress and the database load while it runs. Because the operation is asynchronous, the team checks its status until it completes and then confirms the index settings for each table. The step is done when the operation has finished without errors and the index configuration for each candidate table has been verified in the database.
Retest transaction retry settings
After the index change, the team tests the retry configuration for transactions. Medplum recommends transactionAttempts of 3 to 4 and a 200 ms backoff base delay as a complementary measure, so the team tests those values against its own load and compares them with the current settings. Each setting is changed one at a time so that the effect of the index change and the retry change can be separated. The step is done when the retry configuration that produces the fewest unresolved serialization errors without unacceptable latency is identified and recorded.
Repeat measurements under the same conditions
The team repeats the bulk load several times under the same dataset, concurrency and hardware conditions used for the baseline, and compares each run with the baseline table. Repeated runs show whether the improvement is consistent or was caused by a one-off condition such as cache warmth or a quiet period on shared infrastructure. The results should show fewer serialization errors, fewer slow queries and lower write latency spikes than the baseline. The step is done when the runs are consistent enough to trust, and any run that differs sharply is investigated before the numbers are used.
Record verified throughput in the cutover timeline
The migration lead enters the verified throughput figures into the cutover timeline, along with the Medplum version, index and retry settings, dataset size and environment that produced them. The timeline should show the measured load window for each resource group and state the conditions under which the figure holds, so that a change in version or hardware triggers a re-measurement. Teams should confirm that the production environment is sized like the test environment before relying on the figures. The step is done when the cutover plan cites only measured results from the team's own data and includes a dated re-test step before production load.
How the bulk load, index maintenance and retries interact
The loader sends batches of FHIR bundles to the Medplum server, which writes them to PostgreSQL tables carrying GIN indexes used for search. When a write hits a serialization conflict (SQLSTATE 40001), the server retries the transaction with backoff, governed by the transaction attempt and base delay settings. A super admin runs the asynchronous $db-configure-indexes operation to turn off GIN fastupdate on busy tables, which also runs VACUUM. Check retry counts and write latency before and after that change to confirm it worked.
Loader writes, server retries, and the super admin's index maintenance all touch the same tables.
Measuring throughput so the cutover plan uses real numbers
A bulk load only helps the cutover plan if the team records what it did, at what rate, and what it cost the rest of the system. The six measurements below are taken during trial loads against a self-hosted Medplum server, then reused to size the production window and decide whether GIN tuning and transaction retry settings are needed.
Records per minute by resource type
Record the sustained load rate for each resource type, not one average across the whole run. Patients, Encounters and Observations usually behave differently, and their rates decide the order and the length of each load phase. Log the rate at the start, middle and end of each batch run, because throughput often falls as GIN indexes grow. Use the slowest sustained rate, not the best hour, when you size the window.
Error and 40001 retry counts
Count serialization failures (SQLSTATE 40001), other errors and retries separately for each batch. A rising 40001 count during a trial run is the early sign that the default fastupdate setting on busy GIN indexes is creating write contention. Record whether the transaction retry settings absorbed these failures or whether records were dropped, since dropped records feed the exception log in your validation plan.
Query latency on search-heavy endpoints
Measure response times for the search calls your post-load checks and clinicians depend on while the load runs, such as patient lookup by identifier and name. Run the same queries before the load starts to get a baseline. If latency climbs sharply during the load, the window must allow for a quieter period or a smaller batch size, and you should confirm the GIN tuning steps before the rehearsal.
Vacuum and bloat indicators
Track dead tuple counts, the time of the last autovacuum and analyze run on each large table, and the growth in table and index size after each batch. Bloat that builds up during a load slows later batches and inflates the storage you must provision. Record when you ran VACUUM on the affected tables, so the cutover runbook can schedule it in the window rather than discovering it during the run.
Write latency on shared live traffic
If the migration server also handles production or test traffic, record write latency for those requests across each load run. This is the measurement that shows whether the load is taking capacity from users. Compare it with a run that has no bulk load. The result decides whether the load can run in the day or must be restricted to an off-hours window, and it sets the batch concurrency you can safely use.
Load timeline and rerun cost
Keep one timeline per trial that records each phase, pause, failure and manual intervention with its start and end time. Add the time spent on reruns, index maintenance and recovery. Sum these into the total elapsed time the cutover plan needs for each resource group. Repeat the trial with the same data volume at least once, because a single run rarely shows the variance that a production window must absorb.
What drives the effort and duration of tuning a bulk load
This table lists the factors that change how much tuning a Medplum bulk load needs and how long the rehearsals take, with the direction of each effect and what to confirm in your environment. Read it before setting cutover dates, because the biggest levers are the number of GIN-indexed tables written during the load and whether live traffic shares the server. Most of the risk comes from combining high loader concurrency with the default fastupdate setting.
| Driver | Effect on effort | What to confirm in your environment |
|---|---|---|
| Dataset size per resource type | Larger tables mean more index maintenance and longer VACUUM work, so tuning and rehearsal time grow with volume | Row counts per resource type from the source inventory, and the expected growth during the migration window |
| GIN-indexed tables receiving writes | Each busy GIN-indexed table adds pending-list maintenance and possible 40001 serialization errors, widening the set to tune | Which search-indexed tables the loader writes to, and whether any are written in parallel |
| Loader concurrency | Higher parallel writers raise contention on the same tables and increase serialization errors and retries | Number of parallel workers and batch sizes in the loader, and the retry behavior when a transaction fails |
| Live traffic on the same server | Shared traffic raises write latency and lock contention, so tuning must protect production queries | Whether the bulk load runs on a dedicated server, a separate stack, or during a read-only window |
| PostgreSQL sizing and hardware | Limited memory, CPU, or storage I/O slows VACUUM and index updates and narrows safe concurrency | Instance class, storage type and IOPS, memory settings, and whether replicas are involved |
| Transaction retry settings | Higher transactionAttempts and backoff reduce failed loads but lengthen total load time under contention | Current transactionAttempts and backoff values, and the recommended starting points in the Medplum GIN index performance guidance |
| Number of dress rehearsals | Each rehearsal repeats the full load, index changes and VACUUM, so more rehearsals extend the schedule | Whether rehearsals run on a copy sized like production, and how throughput results feed the cutover plan |
| Version and upgrade path | Upgrades between minor versions must run in sequence and may add post-deploy data migrations that compete with the load | Current Medplum version, target version, and whether any upgrade must finish before the load starts |
What usually goes wrong during large Medplum imports
Most failed or slow Medplum loads trace back to a small set of habits: tuning without a baseline, changing indexes under live traffic, retrying too aggressively, and rehearsing on the wrong volume. The cards below pair each risk with a prevention step you can put into the cutover plan before the first batch runs.
Tuning without a measured baseline
Teams often apply fastupdate changes or retry settings before they know where the time goes. Without a baseline, you cannot tell whether a change helped, and you cannot show the cutover owner why throughput moved. Record write latency, serialization error counts (40001) and load rate for a fixed sample batch before changing anything. Repeat the same measurement after each single change so each adjustment has one clear effect.
Index maintenance during live traffic
Running $db-configure-indexes while clinicians or integrations still write to the same tables adds contention to the work you are trying to speed up. The operation runs VACUUM, so the maintenance itself competes for I/O with the import. Schedule the change in a defined window with write traffic paused or routed elsewhere, and confirm with your operations team who can stop the window if latency climbs.
Retry storms that worsen contention
When transactions fail with serialization errors, aggressive client retries can multiply conflicts and keep the tables busy. Medplum recommends a transactionAttempts value of 3 to 4 with a 200 ms backoff base delay as a complementary measure. Set those values in the loader, then watch the retry rate. If retries keep climbing, the fix is usually lower concurrency in the pipeline, not more attempts.
Skipping VACUUM after heavy loads
Large imports leave dead tuples and bloated index pages behind, which slow later reads and writes even after the load finishes. Teams that declare the load complete without maintenance often see cutover-day queries run slower than the rehearsal did. Confirm that VACUUM ran as part of the index operation, check table and index sizes against the pre-load baseline, and include a post-load query timing check in the acceptance criteria.
Rehearsing below production volume
A load that finishes in minutes on a small dataset can behave very differently at full volume, when index sizes, buffer cache pressure and lock waits grow. Throughput measured on a sample tells you little about the cutover window you need. Rehearse with a dataset that matches production record counts and table sizes, and record throughput so the cutover timeline is built from measured numbers rather than estimates.
Unplanned Medplum version change
Changing the Medplum server version in the middle of a load project can alter how writes, indexes and migrations behave, which invalidates the baseline you measured. Self-hosted Medplum must also be upgraded through each minor version in sequence, and post-deploy data migrations can run for hours or days on large datasets. Freeze the server version for the load and rehearsal, and schedule any upgrade as its own project with its own rollback plan.
Upgrading the server guideQuestions teams ask before tuning a Medplum bulk load
What drives the cost of tuning a Medplum bulk load?
The cost depends on how much of the work your own team can absorb and how much outside help you buy. The main drivers are the size of the import, how many tables and indexes are busy during the load, how many environments you need to test in, and how much measurement and reporting you want before the cutover. One-time work includes profiling the load, applying index changes, testing retry settings and documenting throughput. Recurring cost appears only if you repeat large loads during later migration phases. Ask any partner for a quote that lists each of these items separately, along with who performs the staging runs and who signs off on the production change.
How long does tuning a Medplum bulk load take?
Duration is set by the measurements you need, not by a fixed number of days. Expect the time to grow with the number of resource types loaded, the volume of writes per table, the number of staging runs required to reach a stable throughput figure, and the time needed to run VACUUM and index maintenance between runs. Long-running jobs and the asynchronous $db-configure-indexes operation also add waiting time that does not scale with team effort. Ask for a plan that names the staging runs and the acceptance measurements, and confirm the schedule against your cutover date rather than accepting a generic estimate.
What does the work need from our team?
The work needs a super admin account on your self-hosted Medplum server, a staging environment sized close enough to production to produce believable throughput numbers, and access to PostgreSQL and Redis metrics. Your team also needs to provide a representative sample of the source data, the migration loader or bulk import job, and a named owner who can approve changes to indexes on live tables. Without these, tuning results will not carry over to production. Confirm the staging capacity, the metrics you can export, and the change window before the work begins.
Can our own engineers tune the bulk load without outside help?
Yes, if your team has PostgreSQL operations experience, can run controlled load tests, and has super admin access to the Medplum server. The Medplum GIN index performance documentation describes the per-table fastupdate change, the $db-configure-indexes operation, and the transaction retry settings, so the steps are documented. The skill gap is usually in reading lock waits, interpreting serialization errors (40001) against write latency, and deciding when an index change is safe. Teams that lack this experience can split the work: their own engineers run the import while an outside specialist reviews the measurements and retry configuration.
Is it safe to change GIN index settings on a live Medplum server?
It can be safe when the change is planned, tested in staging, and applied during a window agreed with the business owners. Disabling fastupdate on a busy table and running VACUUM both create load and can hold locks, so the risk depends on table size, concurrent write volume and the time the operation takes. The $db-configure-indexes operation is asynchronous, which means you need to monitor its progress and confirm completion before resuming the import. Confirm with Medplum and your database team how the operation behaves on your Medplum version before running it in production, and keep a rollback plan for the index settings.
Should we hire outside help to tune our Medplum bulk load?
Hire outside help when the cutover date is fixed, the load is large enough that serialization errors or write latency would affect clinical operations, or your team lacks PostgreSQL tuning experience. Outside help is also useful when you need a documented throughput measurement to support a cutover decision. Keep the work in-house when your team has run comparable loads, has staging capacity, and can accept a slower schedule. In either case, ask for a fixed-scope written plan that lists the staging runs, the measurements, the production change steps and the handover documentation before work starts.
What DeployOpen needs from your team to plan a tuned load
Planning a tuned load starts with a target dataset profile that your team writes before any index setting is changed. The profile should list each resource type, its approximate row volume, the share of records that arrive through bulk import compared with steady-state upserts, and which tables will be hit hardest during the window. This is the input that determines whether the GIN fastupdate change and the $db-configure-indexes run belong in the plan at all, and which tables they apply to. Your team should also name the load order and the batch sizes its pipelines use, because these set the concurrency that produces serialization errors (40001) in the first place.
DeployOpen also needs staging environment access that mirrors the self-hosted production topology: the same PostgreSQL and Redis versions, the same server replica count, and comparable instance sizing. Confirm with your platform team that a staging PostgreSQL instance can be reached for measurement, and that a super admin account on the self-hosted Medplum server can run asynchronous operations there and in production. Super admin rights are required to call $db-configure-indexes, so the owner of that access should be named in the written scope, along with who approves running it against a live table. Ask your infrastructure team to confirm how long a VACUUM pass can be tolerated on each table in the production window.
The last input is a rehearsal plan agreed with your migration and clinical leads before the fixed-scope agreement is signed. It should state how many full-volume dry runs will happen, which throughput numbers will be recorded on each run (rows per minute, error counts by type, and write latency during the load), and which thresholds would trigger a change to transactionAttempts or the backoff base delay. DeployOpen can plan, implement and document this tuning on your self-hosted Medplum deployment, and the written scope will record each deliverable and the rehearsal count. Confirm with your own change board which environments and dates require sign-off.
How DeployOpen scopes and delivers a Medplum load and cutover plan
DeployOpen plans, implements and documents self-hosted Medplum inside the client's own infrastructure, so bulk load performance and GIN index tuning are handled as part of the wider migration rather than as a one-off tuning task. The work starts with measured throughput on the client's own data and ends with a runbook the client's team can operate.
How we scope
- Written scope lists the source tables, resource types and bulk load jobs that the performance work will cover.
- We confirm which tables are busy during the load window and which can be locked or reindexed safely.
- Scope records the self-hosted environment, PostgreSQL access level and the super admin accounts that will run the operations.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
How we build
- We run a test load against a copy of production-shaped data and record throughput, serialization errors and slow queries.
- We plan the fastupdate change per table with the async $db-configure-indexes operation and its VACUUM run, then test it in a non-production environment.
- We set transaction retry attempts and backoff delay, then re-measure to confirm the retry settings clear the errors without masking them.
- We feed measured rates into the cutover timeline so load windows reflect real throughput, not estimates.
How we hand over
- Deliverables include the tuning runbook, the index change record and the before and after throughput measurements.
- The runbook gives exact steps to restore default index settings and to check for leftover VACUUM or lock activity.
- Operators are trained on monitoring write latency and serialization error rates during each bulk load run.
- Documentation is written so the client's own team can repeat the load in later migration waves.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers for the self-hosted Medplum environment.
- Support can cover re-running throughput tests after a Medplum minor version upgrade, when load behavior may change.
- We can help review retry and index settings when new bulk loads or high-concurrency workloads are added.
- Confirm with DeployOpen during scoping which support hours, response paths and retest cycles the retainer includes.

