Implement a Thread-Safe Pre-Event Dash Cam Frame Buffer

Last updated: November 29, 2026

Quick Overview

Implement a fixed-capacity ring buffer that stores (timestamp, frame) pairs from a dash cam, overwrites the oldest frame when full, and returns the frames from the last N seconds in order when a safety event fires, safe for one writer and concurrent readers.

Samsara
Software Engineering Fundamentals
Software Engineer
Samsara
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Implement a fixed-capacity ring buffer that stores (timestamp, frame) pairs from a dash cam, overwrites the oldest frame when full, and returns the frames from the last N seconds in order when a safety event fires, safe for one writer and concurrent readers.

When a Samsara AI Dash Cam detects a harsh event, the uploaded clip must include footage from before the trigger, which means the camera is always recording into a bounded buffer. The interviewer checks index arithmetic, overwrite semantics, and basic concurrency safety on embedded-style constraints.

What the Interviewer Expects
  • Use a fixed array with head index and size, no unbounded growth
  • Overwrite oldest on push when full
  • Reconstruct chronological order from the head
  • Guard shared state with a lock and keep the critical section small
  • Filter by time window relative to the newest frame
Key Topics to Cover
Ring buffer
Concurrency
Memory bounds
Embedded systems
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you avoid copying large frames during snapshot?
  • How would you make it lock-free for a single producer and single consumer?
  • Frames vary in size; how would you bound by bytes instead of count?
  • What happens if the camera clock jumps backward?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

push(ts, frame) is called by the capture thread at a fixed rate. snapshot(seconds) is called by the event thread and returns frames with ts >= newest - seconds, oldest first. Capacity is fixed b...

High-Level Design

Preallocated list of capacity slots, head = next write slot, size = number of valid items. The oldest item is at (head - size) % capacity. One lock protects buf, head, size. Snapshot cop...


Submit Your Answer
Markdown supported

Related Questions