Z Zelnoo Allotment Engine
Dispatch Intelligence · Microservice

The Allotment Engine decides who collects, in milliseconds.

A standalone NestJS microservice that matches every home-collection order to the optimal phlebotomist — weighing distance, quality, workload, reliability and experience, then refining the shortlist with real driving distances. Manual dispatch becomes an automated, explainable decision.

NestJS · port 4050 BullMQ queue + sync REST OSRM road distances Haversine geo-scoring
~200ms
Typical assignment time
5-factor
Weighted scoring model
3 levels
Fallback cascade
7 steps
Decision pipeline
What it does

From order to the right person at the door

When a booking needs a field collection, the core platform asks the engine: “who should take this job?” The engine pulls every eligible phlebotomist — both independent partners and center-employed staff — scores them against the job, and returns a ranked decision: assign, retry, or send to manual review. It runs synchronously for urgent jobs and over a BullMQ queue for throughput.

📍

Geo-aware

Haversine distance ranks the field instantly; the top 5 are then refined with real OSRM driving distance & time for drivability-accurate ETAs.

⚖️

Fair by design

A 20% workload weight actively spreads jobs across the team, preventing burnout and protecting service quality at peak.

🎯

Explainable

Every decision returns a confidence score, the reason, alternatives and an estimated arrival time — never a black box.

The scoring model

Five factors, one composite score (0–1)

Each eligible candidate earns a weighted score. Proximity dominates, but quality, fair load distribution and reliability all shape the outcome — and urgent jobs get a priority boost on top.

Proximity
35%
Quality / rating
25%
Workload balance
20%
Reliability
15%
Experience
5%
Priority boost: NORMAL +0 · HIGH +0.05 · URGENT +0.10 added on top of the composite score. Confidence is derived from the gap to the runner-up, so close calls flag themselves for review. Experience adds a skill-tier bonus (Junior→Expert: +0 to +0.3).

The decision pipeline

1

Hard eligibility filter

Online, KYC-verified, not blacklisted, license valid, free capacity, and serving the pickup pincode. Anyone who fails is out before scoring.

2

Enrich & check feasibility

Compute distance, active job count, and whether the candidate can physically reach the slot in time (travel time + 15-min arrival buffer).

3

Score & rank

Apply the 5-factor model; sort descending. Candidates beyond their service radius score zero on proximity.

4

Road-distance refine

Re-score the top 5 with real OSRM driving distance & duration — graceful fallback to straight-line if routing is unavailable.

5

Threshold & decide

If the best score clears the minimum (0.4), assign with alternatives + ETA. Otherwise trigger the fallback cascade.

6

Webhook the result

Async jobs post the decision back to the core API over an authenticated channel, with retries and a dead-letter trail.

Rule sets & constraints

Hard rules first, soft scoring second

Eligibility is non-negotiable — a candidate must clear every hard constraint before they’re even scored.

ConstraintRuleApplies to
AvailabilityStatus must be ONLINEAll phlebotomists
IdentityKYC VERIFIED · not blacklistedIndependent partners
LicenseNot expired (expiry > now)Center-employed staff
CapacityCurrently free / under max concurrent jobsAll
CoveragePickup pincode ∈ service pincodesIndependent partners
Slot feasibilityCan arrive before slot end (+15 min buffer)All

Fallback cascade — never drop a job silently

Pincode expansion

Drop the strict pincode filter and pull the nearest verified, free partners platform-wide, re-filtered by service radius.

Allow overloaded

Permit a second concurrent job for busy-but-capable partners — used only once the free pool is exhausted.

Retry or escalate

Re-attempt up to 3 times (5-min delay), then escalate to manual review so a human can intervene — nothing falls through.

Min score 0.40 Max attempts 3 Retry delay 5 min Avg speed 20 km/h Arrival buffer 15 min Road-refine top 5 Rejections excluded on retry
Connected systems & impact

The hub of field logistics

The engine sits between the order and the field — every other operations surface either feeds it or reacts to its decisions.

CORE API →

Booking orchestrator

The platform calls /v1/allot the moment a home-collection order is paid; the engine returns the assignee and ETA that drive the order forward.

→ PHLEBO APP

Phlebotomist app

An assignment lands instantly in the field worker’s job queue with a push notification — turning a decision into a dispatched collection.

→ CUSTOMER APP

Patient app tracking

The chosen phlebo and ETA populate the patient’s live tracking map — the visible payoff of a good match.

INVENTORY ↔

Kit & stock

Availability assumes the assignee carries a viable collection kit; field stock levels keep the candidate pool realistic.

SENTINEL ↔

Trust & safety

Reliability & cancel-rate signals feed scoring; Sentinel can remove a gaming phlebo from the eligible pool entirely.

→ ADMIN

Manual review queue

When no candidate clears the bar, the decision escalates to the Admin Portal for a human to assign.

Minutes → ~200ms
Assignment latency vs. manual dispatch
Fewer missed pickups
Slot-feasibility gating + auto-retry
Balanced workload
Fairer earnings, lower churn in the field