codebaobab

FDE interview labProduct Features

Video Analytics

Fix a daily view report.

JavaScript40 minutesProduct Features

Challenge brief

Read before you begin

Your mission · Analytics bug fix

Fix the daily view report so creators are paid for the views they actually got.

Lumen pays course creators from a nightly view report, and Finance found the dashboard and the payout file disagree for the same creator. Creator Support has 37 open tickets, and Finance will not release the November payout, due in 5 days, until the numbers match.

  • Target · All public checks
  • Time · 40 min
Skip to round setup

Your assignment

  1. Reproduce the three bugs in the tickets.
  2. Fix how views are assigned to UTC days.
  3. Count each event once, even when it is retried.
  4. Handle the new requirement when it arrives.
  5. Explain each fix in NOTES.md.

The problem

Two numbers for one creator

The dashboard showed 1,284 views. The payout file showed 1,197.

Impact: Finance will not release the November payout.

Views land on the wrong day

Late-night plays and retried events are counted on the wrong date.

Impact: Creators are paid for the wrong month.

Context

Viewers a month
2M
Until payout
5 days
Support tickets
37

Requirements

  • One row per video, ranked by views.
  • Dates are inclusive UTC days.
  • Convert offsets to UTC before choosing the day.
  • A retried event counts once, on its first day.
  • Count distinct viewers per video.
  • The input is never changed.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

Player SDKSends play events
Ingest gatewayAccepts events at least once
EventsAppend-only play events
Report job(Your work)Builds daily view reports
Report storeStores recent reports
Creator dashboardCreators view reports
Payout exportMonth-end revenue file
Read the connections
  • Player SDK → Ingest gateway: at least once
  • Ingest gateway → Events: append
  • Events → Report job: nightly, UTC days
  • Report job → Report store: one per run
  • Report store → Creator dashboard: read
  • Report store → Payout export: month end
  • Player SDK: Sends one play event per playback. Retries reuse the event id.
  • Ingest gateway: Accepts events at least once and appends them unchanged.
  • Events: Append-only play events: id, video_id, user_id, at.
  • Report job: summarizeViews(events, start_date, end_date) in analytics/report.js, split across the window, events, totals and ranking modules.
  • Report store: SQLite run store; keeps the newest 100 reports.
  • Creator dashboard: GET /v1/view-reports and /v1/runs/{id}.
  • Payout export: Finance's month-end revenue-share file.

Data model

Play event

FieldTypeNotes
idstringUnique per play. A retry reuses it.
video_idstringThe video played.
user_idstringThe viewer.
atISO 8601 timestampThe client's local time, with Z or an offset such as -05:00.

Report row

FieldTypeNotes
video_idstring
viewsintegerRetained events for the video in the range.
unique_viewersintegerDistinct user_id values among those events.

Details

Full requirements

Functional

  1. Return one row per video, {video_id, views, unique_viewers}, sorted by views descending, then video_id ascending. The dashboard and the export both depend on this order.
  2. start_date and end_date are inclusive YYYY-MM-DD UTC days. Each event's at is an ISO timestamp with Z or an explicit offset; convert it to UTC before deciding its day, because creators and viewers are in every time zone.
  3. Keep the first occurrence of each event id before filtering by date. The gateway retries, and a retry must never move a view into another day, or into another month's payout.
  4. Count every retained event as a view, and distinct user_id values as viewers.
  5. Do not mutate the input. Reject a reversed date range with an error whose message mentions date.

Non-functional

  • Scale: production runs the report over about 30 million events a day inside a 10-minute nightly window. Keep it to one pass over the events, with memory proportional to the distinct event ids.
  • Determinism: the same input always produces the same output, row for row, because Finance audits the payouts against it.
  • Idempotency: rerunning a day must give the same report; nothing may depend on arrival order beyond "first occurrence wins".

Out of scope

  • The HTTP layer, authentication and the report store: they work, and the checks do not exercise them.
  • Events that arrive more than a day late. The report runs once per night; how you would handle late events is a debrief question.
  • Payout amounts. Finance converts views to money; you only count views.
Files you are given · 4
  • samples/events-2026-10-14.json Five events for October 14, including a retry either side of midnight UTC and two plays with a -05:00 offset.
    [
      {
        "id": "evt-9f31",
        "video_id": "course-intro",
        "user_id": "u-118",
        "at": "2026-10-14T09:12:40Z"
      },
      {
        "id": "evt-9f32",
        "video_id": "course-intro",
        "user_id": "u-204",
        "at": "2026-10-14T18:03:11-05:00"
      },
      {
        "id": "evt-a001",
        "video_id": "lesson-2",
        "user_id": "u-118",
        "at": "2026-10-13T23:59:58Z"
      },
      {
        "id": "evt-a001",
        "video_id": "lesson-2",
        "user_id": "u-118",
        "at": "2026-10-14T00:00:04Z"
      },
      {
        "id": "evt-9f40",
        "video_id": "lesson-2",
        "user_id": "u-310",
        "at": "2026-10-14T23:30:00-05:00"
      }
    ]
  • samples/report-2026-10-14.json The report Finance expects for that day. evt-a001 belongs to October 13; evt-9f40 is October 15 in UTC.
    [
      {
        "video_id": "course-intro",
        "views": 2,
        "unique_viewers": 2
      }
    ]
  • logs/ingest-2026-10-14.log The gateway accepting evt-a001 twice, six seconds apart across midnight UTC, and the report run that counted it.
    2026-10-13T23:59:58.912Z gateway accepted event=evt-a001 video=lesson-2 user=u-118 retry=0
    2026-10-14T00:00:04.377Z gateway accepted event=evt-a001 video=lesson-2 user=u-118 retry=1 reason=client_timeout
    2026-10-15T04:30:01.023Z gateway accepted event=evt-9f40 video=lesson-2 user=u-310 retry=0
    2026-10-15T06:00:00.000Z report run=r-2291 range=2026-10-14..2026-10-14 events=5 rows=2
  • metrics/dashboard-vs-payout-2026-10.csv October totals per creator: the disagreement Finance escalated.
    creator,dashboard_views,payout_views,difference
    cr-0042,1284,1197,87
    cr-0107,642,640,2
    cr-0311,15520,14968,552
Tickets · 3
  • BUG-101 A play at 23:30 with a -05:00 offset is reported on the wrong day Reported by Dana (product)

    Expected evt-9f40 (23:30 at -05:00, which is 04:30 UTC on October 15) is not in the October 14 report.

    Actual It is counted on October 14, the day written in its local timestamp.

  • BUG-102 A retried event whose first delivery was outside the date range is counted as a view Reported by Ifeoma (data)

    Expected evt-a001 counts once, on October 13, where it was first delivered; lesson-2 has no view from it on October 14.

    Actual The retry at 00:00:04 is counted as a view on October 14.

  • BUG-103 Every video shows zero unique viewers Reported by Sam (on-call)

    Expected unique_viewers is the number of distinct user_id values for the video, for example 2 for course-intro on October 14.

    Actual unique_viewers is 0 for every video.

What you hand in
  • Every public check passing, including the new requirement when it arrives.
  • NOTES.md: for each ticket, the cause, the fix and the check that proves it, one line each.
  • Your answer to the interviewer's follow-up and the debrief questions.
How the work is judged
Breaking down the work
Names deduplication before the date filter as the riskiest rule before writing any code.
Directing the assistant
Asks the assistant for a plan, with no code, and gives it the specific failing case.
Checking the work
Reproduces BUG-102 with the sample retry before changing code, then reruns the checks after each fix.
Judging the assistant
Catches the assistant moving deduplication after the date filter, or converting offsets after taking the date.
Correct result
All checks pass, including the follow-up, with ordering and errors exactly as specified.
Explaining the work
NOTES.md explains each cause in one line a Finance analyst could follow.
Trade-offs to discuss
  • Memory: a set of every event id seen versus the correctness of first-occurrence-wins across days.
  • Normalizing time zones at ingest versus in the report, and what each means for old data.
  • Why a short play must still claim its event id once only qualifying plays count as views.
How you are graded
  • Decomposition 15%
  • Prompting the assistant 15%
  • Verification 20%
  • Judgment about AI output 15%
  • Correctness 25%
  • Communication 10%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

Here is a video dashboard whose daily report overcounts. Use the AI assistant however you like; I am more interested in how you check its work than in how fast you type. Start by telling me which requirement you think is easiest to get wrong, then make the checks pass.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 6 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • Why must a short play still claim its event id when it does not count as a view?
  • If the report had to include events that arrive a day late, what would you change and how would you test it?