Design a task management system with TTL
CoinbaseSoftware Engineer · Online AssessmentLast updated
This question evaluates the ability to design in-memory data models and algorithms for time-based task assignment semantics, including TTL-based expiration, per-user quotas, priority-based listing, and correct handling of multiple concurrent assignments and completion rules.
Task Management System (in-memory)
Design and implement an in-memory task management system that supports tasks, users, task assignment with TTL (time-to-live), and time-based completion/expiration rules.
Entities
- Task:
id(unique),name,priority(higher number = higher priority, or clearly define). - User:
id(unique), and a quota = maximum number of active task assignments the user may have at once. - Task Assignment: assigns a task to a user at a
startTime, with attl(duration). The assignment is active on[startTime, startTime + ttl)and expired at or afterstartTime + ttl.
Requirements / APIs
- Task CRUD
- Create a task.
- Get a task by id.
- Update a task (e.g., name/priority).
- Task listing
- Return the top N tasks by priority.
- Return the top N tasks by priority whose name contains a given substring.
- Users + assignment with TTL
- Add a user with a quota.
- Assign a task to a user with a TTL at a given
startTime. - You may assign multiple tasks to the same user.
- You may assign the same task to multiple users.
- (If the same task is assigned multiple times to the same user at different start times, treat them as distinct assignments.)
- List a user’s active tasks at a given time
t.
- Completion + expiration rules
- Complete a task for a user at a given time
t. - You cannot complete an expired assignment.
- If there are multiple active assignments for the same
(userId, taskId), completing thattaskIdcompletes the one with the earliest startTime. - List a user’s expired tasks at a given time
t.
Clarifications to state during the interview
- How ties in priority are broken (e.g., higher priority first, then by
taskIdlexicographically). - Whether “list tasks by priority” returns tasks (unique by taskId) or assignments (can repeat taskId). (Common approach: listing in (2) is over tasks; user lists in (3)/(4) are over assignments.)
- Input constraints and expected complexity (aim for efficient queries; in-memory only).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.