Katkat

Design a task management system with TTL

CoinbaseSoftware Engineer · Online Assessment

Last 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 a ttl (duration). The assignment is active on [startTime, startTime + ttl) and expired at or after startTime + ttl.

Requirements / APIs

  1. Task CRUD
  • Create a task.
  • Get a task by id.
  • Update a task (e.g., name/priority).
  1. Task listing
  • Return the top N tasks by priority.
  • Return the top N tasks by priority whose name contains a given substring.
  1. 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.
  1. 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 that taskId completes 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 taskId lexicographically).
  • 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).