Design a Regional Lead Allocation System
Assign leads to eligible regional agents without exceeding active capacity, then release assignments and read each agent’s current work.
Problem statement
For this exercise, assume agents have fixed active-lead capacities and configured regions they serve. An incoming lead has a stable ID and one region. Assign it to an eligible agent with a free slot, release the exact assignment when work ends, and report an agent’s current active leads and count.
A lead has at most one current assignment and no agent may exceed capacity, including during concurrent requests. Any eligible agent with room is a valid winner; fairness and automatic redistribution are outside scope.
For this exercise, assignment and release use durable caller request identity. Repeating a request recovers its original occurrence rather than allocating again. A released lead may be assigned by a new logical request, but a delayed release of the old occurrence cannot affect its new owner.
Current-lead reads return one consistent snapshot of committed assignments. Show the core entities, short flow pseudocode, concurrency control, region lookup indexes and safe cache roles. Agent administration, capacity changes and region-membership changes are outside this exercise.
What to build
- Assign an unassigned lead to one agent who serves its region and has unused active capacity, with an explicit no-capacity or retryable outcome when appropriate.
- Release the named active assignment once and free exactly its capacity; an old release cannot affect a later assignment of the same lead.
- Return an agent’s current active lead identities and count from one committed snapshot.
- Recover the same logical assignment outcome after caller retries or a lost response without creating another occurrence.
At scale
- For this exercise, assume 10,000 agents across 50 regions and at most 100 active leads per agent.
- For this exercise, peak assignment/release load is 2,000 mutations per second and current-lead reads 10,000 per second; one region can receive 40 percent of mutation traffic.
- For this exercise, healthy assignment/release target 300 milliseconds p 95 and per-agent current-lead snapshots 200 milliseconds p 95.
- For this exercise, acknowledged assignment and release changes survive an application-instance crash; unavailable authority produces an explicit retryable or uncertain outcome rather than a guessed success.