KatInterview

Time-Indexed Service for Multi-Topic Vehicle Recording Files

System DesignModel answer
MediumModel answerSystem Designmcapprotobufsqlite

Last updated

Design and build a service that ingests recorded vehicle sessions from MCAP files, stores them with a time index, and exposes APIs to list sessions and fetch messages by timestamp.

You are given a set of recorded vehicle drives, each called a run. Runs are stored in MCAP, an open container format for timestamped, multi-topic log data. Each run holds messages on topics such as camera (images or video frames) and location (position data). The MCAP files carry their own schemas, and every message payload is encoded with Protocol Buffers. Every message has a timestamp, and timestamps differ between messages and between topics.

Conceptually, the data is laid out like this:

run_a
  camera
    message_1
    message_2
  location
    message_1
    message_2

Build a small service over this data. You may use an AI coding assistant, and you may pick the language and storage (Python with SQLite is a reasonable fit for a short session). The full feature list is long, so decide which features are required and build those first. The two known requirements are:

  • list all runs;
  • query messages by timestamp, which means the stored data needs an index on time.

You will finish with a demo and be asked how you worked with the assistant.

Part 1: Ingest and store the runs

Read every run, decode its messages, and store them so they can be queried. One option keeps message metadata (run, topic, timestamp) apart from raw payloads; another places every decoded message in a single database. Choose one and justify it.

Cover:

  • how you read MCAP, handle schemas and Protobuf decoding, and which timestamp you keep;
  • the data model for runs, topics and messages, and where large payloads such as images live;
  • one store versus split metadata and payload storage, including consistency;
  • ingestion that is fast and safe to re-run.

Part 2: List runs and query by timestamp

Design and implement the API: list all runs, and fetch messages by timestamp. Timestamp queries must be fast.

Cover:

  • endpoints, and paging for large results;
  • index design, and how you verify the database really uses the index;
  • timestamp units, precision and boundary semantics;
  • behavior for unknown runs or topics and for windows with no messages.

State which clarifying questions you would ask first (for example: which timestamp to query on, whether a query is a range, an exact value or a nearest match, and whether clients need decoded payloads or only metadata).

Part 3: Working with an AI assistant and presenting

Explain how you would use the assistant to explore unfamiliar data and a long specification, how you make sure its output is correct, and how you would present the result (demo, tests, documentation). Expect the question: "How did you interact with the AI?"

Hints

Hint 1

Pin down the query semantics first: which timestamp (log time vs publish time vs a field inside the payload), and whether queries are ranges, exact matches or nearest-message lookups. This determines the index.

Hint 2

Store timestamps as 64-bit integers in their native unit (MCAP uses nanoseconds), and create a composite index such as (run_id, topic, timestamp) so a range scan is a single index seek. Check it with EXPLAIN QUERY PLAN.

Hint 3

Keep large camera payloads out of the hot index path (blob column in a separate table, or files referenced by path), and use keyset paging on (timestamp, id) instead of OFFSET.

Hint 4

For the AI-assistant part, describe a loop: let it summarize the spec and inspect the files, you decide priorities, then verify with tests built from facts you can check independently (message counts, first and last timestamps).