Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Project Factory - Enhancements & Benchmarking

Overview

Project-factory is the system that sets up a full health campaign — think of a large-scale vaccination or health-worker deployment program — from a single Excel file upload. In one go, it needs to:

  • Create the entire project hierarchy — one entry for every geographic area ("boundary"), which can be up to ~21,000 areas for a national campaign.

  • Register all the physical facilities (clinics, centres, etc.) involved.

  • Create user accounts for every field worker across four different backend systems.

  • Map all staff, facilities, and supplies to the right projects — over 100,000 mapping records for a large campaign.

In plain terms: imagine onboarding 20,000 locations, 10,000 facilities, and 20,000 employees — plus linking each employee, facility, and supply item to the right project — all from one spreadsheet upload. That's what this system automates.

The two problems this release fixes

Before this release, running a large campaign (20,793 areas / 10,000 facilities / 20,000 users) had two serious problems:

  1. It was painfully slow. The system processed everything one item at a time — one HTTP request per project, per user, per mapping — like a single checkout line serving thousands of customers. A full campaign took over six and a half hours.

  2. It failed unpredictably, even though nothing was actually wrong. Campaigns would show hard failures like PROJECT_CONFIRMATION_FAILED. Thousands of user accounts would get permanently marked as failed. Newly added facilities would get stuck showing "pending" forever and never recover.

    What was really happening: in every single one of these cases, the record the system was "looking for" did exist — it just hadn't finished being saved yet by the time the system checked for it. It's like calling a warehouse two seconds after placing an order and being told "we don't have that item," when really it just hasn't been shelved yet. The system was treating this temporary delay as a permanent failure.

Why both problems had to be fixed together

Making the system faster (problem #1) actually makes problem #2 worse — the faster things move, the more likely the system is to check for something before it's finished saving. So this release fixes both at once:

  • Speed improvements (bulk operations, parallel processing, smarter batching) make campaigns fast.

  • Consistency improvements (waiting/confirming before checking, "defer instead of fail" logic) make sure that speed doesn't cause new false failures.


Enhancements List

#
Change
Type
Plain-Language Impact
Measured Impact

1

Bulk project creation — create many projects in one request instead of one at a time

Speed improvement

Setting up all 20,793 project areas is now ~5x faster

~60 min → 5–13 min

2

Bulk mapping creation — link staff/facilities/resources to projects in batches, with double-checking

Speed improvement

Linking everything to the right project no longer takes hours

5 h 54 m → 7.6 min (~37× faster per record)

3

Project "parent confirm" fix — wait long enough, and smartly, before checking if a project was saved

Bug fix

Stops campaigns from being wrongly declared "failed"

Eliminates recurring PROJECT_CONFIRMATION_FAILED errors

4

Worker-creation "defer guard" — don't permanently fail a user account just because a check was too early

Bug fix

Field workers no longer lose their accounts due to timing issues

1,008 false permanent failures per run → 0

5

Facility persistence gate — wait for facility data to finish saving before checking on it

Bug fix

New facilities no longer get stuck "pending" forever

Fixes facilities silently stuck in limbo

6

Infrastructure tuning — more parallel processing lanes, bigger batches, more server capacity

Behind-the-scenes tuning

This is what makes all the above improvements actually deliver the 24-minute result

Enables the full 16× speed-up


Architecture - How a Campaign Flows Through the System

In plain terms: think of this as an assembly line with several stations. Here's what happens, in order, when someone uploads a campaign spreadsheet:

  1. Upload — An administrator uploads the filled-in Excel template.

  2. Ingestion — The system reads and checks every row of the spreadsheet, then saves each row to its own database table. This saving step happens in the background, not instantly — a detail that matters a lot for the fixes below.

  3. Parallel creation — Three separate "assembly lines" now run at the same time instead of one after another:

    • Creating projects (one per geographic area)

    • Creating facilities

    • Creating user accounts for field workers

  4. Mapping — Once creation is done, the system links every staff member, facility, and supply item to its correct project. This is called "mapping," and it repeats in cycles until everything is linked.

  5. Credentials — Finally, login credentials are generated for all the new user accounts, and the campaign is marked "created" — done.

The three guarantees that now hold everywhere

For a non-technical reader, the following three rules are the heart of this release — every fix below is really just an application of one of them:

  • "Look only after it's actually there." Every time one step in the assembly line needs to read something another step just created, it now waits and confirms that the data has actually finished saving — instead of checking immediately and assuming "not found" means "doesn't exist."

  • "Never create the same thing twice." Every creation step first checks whether the record already exists before creating a new one. This means if a campaign is retried (say, after a network hiccup), it picks up where it left off instead of creating duplicates.

  • "Running things in parallel doesn't risk mixing things up." Even though many things now happen simultaneously for speed, the system guarantees each record is handled by exactly one process, so nothing gets duplicated or double-counted — this was specifically tested and verified with real large-scale data.

System block diagram


Enhancements in Detail

Bulk Project Creation

The problem before: Each of the 20,793 project areas was created with its own separate request, one after another — like a bank teller serving one customer at a time with 20,000 people in line. This alone took about an hour, and the longer it ran, the more chances there were for something to glitch along the way.

The fix: The system now sends projects in batches of 100 rather than one at a time, with up to 5 batches running simultaneously. A small pause between batches keeps the backend from being overwhelmed. Crucially, the very first project of a batch is double-checked ("confirmed") before its "child" projects underneath it are created, ensuring the hierarchy is built correctly.

There's also a safeguard: before creating anything, the system first checks what projects already exist for this campaign, so re-running a campaign never creates duplicates.

Result: This phase dropped from about an hour to 5–13 minutes. If anything ever goes wrong with this new approach, there's an instant "off switch" (a configuration setting) that reverts to the old, slower-but-proven one-at-a-time method.

Sequence — bulk project creation with paced waves + parent confirmation

Bulk Mapping Creation (Linking Staff, Facilities & Resources to Projects)

The problem before: Every single link between a staff member/facility/resource and its project — 113,172 of them on a large campaign — was created one at a time. This one phase alone took almost six hours.

The fix: Mappings are now sent in batches to a bulk creation service. Because this bulk service works in the background (it says "got it, I'll get to it" rather than "done" immediately), the system now double-checks afterwards that each mapping was actually completed, and records the confirmed result. If a mapping can't be confirmed yet, it's simply tried again in the next cycle — nothing is ever marked as done unless it's actually verified. No record is ever guessed complete.

Sequence — bulk mapping with confirm-by-search + reconciler

Additional safety nets added:

  • Duplicate detection — if two spreadsheet rows accidentally try to create the same mapping, the system now flags this clearly instead of silently ignoring it.

  • Isolated failures — if one batch fails, it doesn't affect any other batch.

  • Safe retries on check failures — if the "did this work?" check itself fails, the record is simply retried, not marked as failed.

  • A safety switch for staff mappings specifically — testing found that on some backend versions, staff mappings silently didn't work through the new bulk method (it looked successful but created nothing). So staff mappings default to the older, proven one-at-a-time method unless a specific setting confirms the new method is safe to use.

Why batch size mattered so much: double-checking a batch takes roughly the same amount of time (8–15 seconds) whether the batch has 30 records or 300. So making batches 10x bigger (30 → 300 records) let that fixed "checking cost" cover 10x more work at once — like inspecting a truck full of boxes once, rather than inspecting each box's own truck. This single change was responsible for a large part of the overall speed-up.

Project "Parent Confirm" Fix — Stopping False Failures

What people were seeing: Large campaigns would suddenly fail with an error like PROJECT_CONFIRMATION_FAILED — and confusingly, if you just tried again, it would work fine, because the project was actually there all along.

What was really happening: When a project is created, its ID comes back right away, but the actual record takes a little longer to finish saving in the background. The system used to only wait a fixed 6 seconds before double-checking a project existed. Under heavy load (creating 20,000 projects at once), that 6-second wait wasn't nearly long enough — the system would give up too early and wrongly declare the whole campaign dead.

The fix, two-pronged:

  1. Slow down the creation itself slightly (small pauses between batches) so the backend has time to keep up.

  2. Make the waiting/checking period configurable and longer — up to about 30 seconds — but design it to move on immediately the moment the project is confirmed, so healthy campaigns aren't slowed down at all (they typically confirm within 2–4 seconds).

Result: This specific failure has not happened once since the fix was deployed.

Worker-Creation "Defer Guard" — Turning False Failures into Safe Retries

What people were seeing: After a fast batch of new user accounts was created, hundreds or even thousands of those accounts would get permanently marked as failed with an error like INDIVIDUAL_NOT_FOUND — even though those very accounts and their underlying records were completely fine and existed in the database.

What was really happening: A separate lookup system (which indexes records for searching, a bit like updating a library's card catalogue after new books arrive) takes a little time to "catch up" after new records are created. Under heavy load, that catch-up time occasionally spiked to as long as 32 seconds — longer than the system's old 20-second wait. When the wait ran out, the system used to just go ahead anyway and try to create the worker record — which then permanently failed because the lookup wasn't ready yet.

The fix, two layers:

  1. Wait longer, but smartly. The waiting window was extended to 50 seconds (based on the actual worst-case delay observed, plus a safety margin) — but it still exits immediately the moment things are confirmed ready, so well-behaved campaigns aren't slowed down at all.

  2. The actual "guard": if a few records still aren't ready even after the longer wait, the system no longer tries to force them through (which would permanently fail them). Instead, those specific records are marked "deferred — try again later" and simply skipped for now. A routine retry of the campaign picks them up automatically once they're ready — by then, the lookup has long since caught up.

Sequence — user creation: bulk with per-user fallback + consistency gate + defer guard

A bonus safety net (HRMS fallback): the system always tries to create user accounts in one big efficient batch first. But if that batch gets rejected for any reason, it automatically falls back to creating those same accounts one by one instead of giving up. In one real test run, two-thirds of the batch attempts failed and fell back this way — and all 20,000 users were still successfully created in the end. Nothing was lost.

Measured effect: the number of accounts falsely marked as failed dropped from 1,008 in one run to zero in the next two runs — even while the system was running faster than before (~1,500 new users per minute).

Facility Persistence Gate — the Last Piece of the Puzzle

What people were seeing: On a spreadsheet that mixed existing facilities (already had a code) with brand-new facilities, the existing ones completed fine — but the new ones would get stuck showing something like 6/1006 completed, 0 failed, 1000 pending and just... never move past that.

What was really happening: New facility rows are saved to the database in the background, the same as everything else in this release. But the part of the system responsible for creating facilities was checking the database immediately, before those new rows had finished saving. Seeing nothing to do yet, it simply gave up and never checked again — leaving those rows stuck forever. It looked like "old facilities work, new ones are broken," but that was a coincidence: existing facilities (with a code already) don't need this creation step at all, so they were never affected by the bug in the first place.

The fix: This step now works exactly like the other steps already described — it waits and confirms that the expected number of new facility rows has actually finished saving before it starts checking for them. Campaigns that were already stuck like this simply need to be retried once, and they'll complete correctly — the data was there all along, just waiting to be picked up.


Configuration Reference (For Technical Teams)

The section below is intended for engineers deploying or tuning the system. Non-technical readers can safely skip to Section 6 (Benchmarking).

Each value below was tuned against measurements on the test environment (unified-UAT) and can be changed through configuration — no code changes needed.

Environment (project-factory)

Kafka Partitions

In plain terms: a "partition" is like a checkout lane — one lane can only be worked by one cashier at a time, no matter how many cashiers are on staff. Adding more lanes lets more work happen simultaneously. These changes are permanent (they survive restarts and deployments) and are always safe to increase.

Topic (what it carries)
Lanes (Partitions)
Carries

hcm-user-create-batch

4

user-creation batches (150 users each)

hcm-mapping-batch

4

mapping batches (300 rows each)

hcm-facility-create-batch

3

facility-creation batches

Service Resources

Service
Setting
Why (Plain Language)

egov-user

4 replicas, CPU limit 4000m

This service handles password security, which is deliberately slow and CPU-intensive on purpose, for security reasons. It just needed more computing power to keep up with bursts of new accounts. Security was never weakened for speed — the password-hashing strength stayed exactly the same.

health-hrms

4 replicas

Handles the full chain of creating a user's account, personal record, and employee record.

worker-registry

2 replicas

Handles field-worker record validation.

Redis (shared cache)

memory limit 1Gi

The cache used to run out of memory and crash repeatedly under load, which made the "false failure" problems described above even worse. Giving it more memory fixed the crashing.


Benchmarking Results

Measured on a realistic test environment with a national-scale campaign: 20,793 geographic areas / 10,000 facilities / 20,000 users. Here's how the final, best-performing run broke down:

Phase
Duration
Rate

Reading & validating the spreadsheet

~2.5 min

—

Creating projects, facilities & users (in parallel)

16.3 min

~1,500 new users/min

Linking staff/facilities/resources (50,793 links)

7.6 min

~6,700/min (larger campaigns sustain 8,000–9,000/min)

Generating login credentials

0.6 min

—

Total, start to finish

24.4 min (core processing: ~21.8 min)

The improvement over time

As the team tuned the system over the course of a week, using the same test environment each time, total campaign time dropped like this:

6 h 41 m → 1 h 24 m → 43 m → 41 m → 34 m → 24.4 m

That's roughly a 16× improvement from where it started. And importantly, the last two runs completed perfectly — zero failed user accounts, zero stuck workers, and zero mapping failures. Speed and correctness were achieved together, not traded off against each other.

A note on how "time" is measured: there are two honest ways to measure this. "Click-to-created" is what a user actually experiences, including the ~2.5 minutes it takes to read the spreadsheet. "Processing time" measures only the actual data-creation work. When you see two slightly different numbers for what looks like the same run, this is almost always the reason.


Upgrade & Deployment Notes (For Technical Teams)

  1. Order matters: database updates (new columns for tracking mapping retries and errors) must be applied before the new software version is rolled out — the system needs those columns to exist for both old and new campaigns.

  2. Apply the new configuration values (Section 5.1) as part of the deployment — the update rolls out automatically. Double-check the settings actually took effect on a fresh server after deploying.

  3. Apply the Kafka partition increases (Section 5.2) once per environment. Always safe to increase; just confirm there's no backlog of unprocessed messages before making the change.

  4. This release only adds new information to existing messages — it doesn't change or remove anything other systems rely on, so it's safe alongside anything else reading those messages.

  5. After upgrading, re-run any campaign that has stuck or deferred records — the retry is safe to run and will automatically sweep up and finish anything left in limbo, in a single pass.

  6. Instant rollback options, no need to redeploy anything: if any of the new bulk features cause issues, they can each be individually switched back off through configuration — projects, mappings, and staff mappings each have their own independent "off switch" back to the old, proven behaviour.


Glossary (Quick Reference)

Term
Plain-Language Meaning

Campaign

A full health program rollout — projects, facilities, workers, and supply links, all set up together.

Boundary

A geographic area (e.g., a district or village) that gets its own "project" record.

Mapping

Linking a staff member, facility, or supply item to the project it belongs to.

Bulk creation

Creating many records in one request instead of one at a time — much faster.

Confirm-by-search

Double-checking that something was actually saved, instead of just trusting an initial "OK" response.

Persistence / persisted

The point at which data has actually finished being saved to the database (as opposed to just being "in progress").

Idempotent

Safe to repeat — running the same action twice doesn't create duplicates or cause harm.

Defer / deferred

Instead of permanently failing something due to a timing issue, it's set aside to be automatically retried later.

Partition (Kafka)

A "lane" of parallel processing — more lanes mean more work can happen at the same time.

Last updated

Was this helpful?