This one built on two prior parts so by the time we got here I thought I had a handle on it.
Start by clarifying requirements and constraints, then propose a design that combines a sticky mapping (account to worker) with an eligibility check and a fallback mechanism. Walk through the data structures and a sample stream to demonstrate correctness and efficiency, and discuss trade-offs like consistency and scalability.
Pro tip: Emphasize the importance of handling worker unavailability and reassignment gracefully—mention how you'd detect failures and update the sticky mapping to maintain correctness. Also, discuss how to avoid hotspots by considering load balancing in the fallback.
Ask about worker capabilities (task types supported), definition of 'earliest-free', persistence requirements, and scale (number of accounts, tasks, workers). Confirm whether sticky routing is strict or best-effort.
Propose a hash map from account ID to worker ID for sticky routing, a map from worker ID to supported task types, and a priority queue or sorted structure to track worker availability for fallback.
For each task, check if the account has a sticky worker; if that worker supports the task type and is available, assign. Otherwise, find the earliest-free eligible worker from the fallback structure and update the sticky mapping.
Simulate a sequence of tasks from different accounts, showing how assignments are made, how fallback triggers when a worker is busy or ineligible, and how the sticky mapping updates.
Cover consistency (e.g., handling worker failures), scalability (sharding by account), and potential improvements like load-aware fallback or TTL for sticky mappings.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.