← Applied intuition Interview Insights

Applied intuition·Software Engineer·Onsite - System Design / Architecture·Senior

Senior
May 2026

Summary

Applied Intuition system design round for a software engineer role. The whole thing was focused on building a task scheduler from scratch, which sounds straightforward until you actually have to talk through edge cases for 45 minutes.

Questions Asked (1)

Q1

Design a single-CPU, single-thread task scheduler with APIs for one-time tasks at an absolute time, one-time tasks after a delay, and periodic tasks that repeat on a fixed interval. Walk through the data structure, the core loop, and how you handle late wake-ups, clock drift, and cancellation.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I went straight to a min-heap sorted by next-fire time, which felt right and they didn't push back on it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints (single CPU, single thread, API semantics). Then propose a min-heap keyed by next execution time, explain the core loop that sleeps until the earliest task, and discuss handling of late wake-ups, drift, and cancellation. Conclude with trade-offs and potential optimizations.

Pro tip: Emphasize that periodic tasks should be rescheduled based on their scheduled time, not actual wake-up time, to prevent drift accumulation. Also, mention that cancellation can be lazy (mark as cancelled) to avoid O(n) removal from the heap.

1. Clarify requirements and API design

Confirm assumptions: single CPU, single thread, tasks are independent, and APIs for one-time absolute, one-time delayed, and periodic tasks. Define method signatures and return handles for cancellation.

2. Choose data structure and core loop

Use a min-heap (priority queue) ordered by next execution time. The core loop peeks the earliest task, sleeps until its time (or until a new earlier task arrives), then executes and reschedules if periodic.

3. Handle late wake-ups and clock drift

For late wake-ups, execute immediately and log the delay. For periodic tasks, compute the next run time as previous scheduled time + interval (not actual time) to avoid drift; optionally skip missed intervals if the system was suspended.

4. Implement cancellation and thread safety

Use lazy cancellation: mark tasks as cancelled and skip them when popped. For thread safety (if APIs can be called from other threads), protect the heap with a mutex and use a condition variable to wake the scheduler when a new task is added.

5. Discuss trade-offs and edge cases

Cover trade-offs: heap vs. timing wheel, precision vs. overhead, and handling of clock changes. Mention edge cases: empty heap, task execution time exceeding interval, and system sleep.

Key Points to Mention

  • Min-heap (priority queue) for efficient retrieval of the next task to run.
  • Core loop: peek earliest task, sleep until its time, execute, and reschedule periodic tasks.
  • Late wake-ups: execute immediately and consider skipping missed periodic intervals.
  • Clock drift: reschedule periodic tasks based on scheduled time, not actual wake-up time.
  • Cancellation: lazy cancellation with a flag to avoid O(n) heap removal.
  • Thread safety: mutex and condition variable to handle concurrent API calls and wake the scheduler.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.