Grant Non-Overlapping Track Authorities Under Concurrent Requests
Last updated: November 29, 2026
Quick Overview
Implement a thread-safe registry that grants a track authority (track id, milepost range, time window) only if it does not overlap an active authority on the same track in both space and time, and supports releasing authorities.
Bnsf
November 29, 20260
0
0 solved
Implement a thread-safe registry that grants a track authority (track id, milepost range, time window) only if it does not overlap an active authority on the same track in both space and time, and supports releasing authorities.
Dispatching systems at a railroad must never hand two crews overlapping authority on the same piece of track, and requests arrive concurrently from many dispatchers and devices. This BNSF style onsite question checks interval overlap logic, check-then-act race conditions, and lock granularity.
What the Interviewer Expects
- Defines overlap precisely, including touching boundaries
- Identifies the check-then-insert race and makes it atomic
- Uses per-track locks instead of one global lock
- Validates and normalizes inputs such as reversed mileposts
- Discusses moving the invariant to the database for multi-node deployments
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you enforce this across several service instances?
- Active authorities per track grow to thousands. What data structure speeds up the conflict check?
- How do you handle an authority that must span two tracks atomically?
- What should happen if the process crashes after granting but before the dispatcher is told?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
request(track, mp_start, mp_end, t_start, t_end) returns a new authority id or the id of the blocking authority. release(track, id) frees it. Two authorities conflict when they are on the same tra...
High-Level Design
The bug to avoid is check-then-act: two threads both scan, both see no conflict, both insert. The scan and insert must be atomic per track. A single global lock is correct but serializes the whole net...