Gangnam Style Broke the Counter

Easy

· Backend

Incident

SEV-3

Time to fix: 10 min

Failing checks on the shipped build

  • crossing two billion keeps counting up

    expected 2147493000 but got -2147474296

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

YouTube · 2014

Inspired by 2014, when PSY's "Gangnam Style" blew past 2,147,483,647 views and YouTube publicly admitted their view counter needed an upgrade to 64 bits.

ViewCounter.java is still on the old math.

Code map

class ViewCounter {
    static long addViews(long current, long delta) {
        int next = (int) current + (int) delta;
        return next;
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

Gangnam Style Broke the Counter — Java Bug Hunt

Inspired by 2014, when PSY's "Gangnam Style" blew past 2,147,483,647 views and YouTube publicly admitted their view counter needed an upgrade to 64 bits.

  • Language: Java
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Overflow, Counters
  • Modelled on: YouTube · 2014
  • Visible tests: ordinary counting works; crossing two billion keeps counting up
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-3
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • crossing two billion keeps counting up — expected 2147493000 but got -2147474296

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Inspired by 2014, when PSY's "Gangnam Style" blew past 2,147,483,647 views and YouTube publicly admitted their view counter needed an upgrade to 64 bits.

ViewCounter.java is still on the old math.

Bug report

BUG-PSY · Reported by: analytics

addViews(current, delta) must keep counting past Integer.MAX_VALUE. Observed: the most-watched video on the platform reports -2,147,473,648 views.

Logs

[stats] video=9bZkp7q19f0 views=-2147473648

The code as shipped

ViewCounter.java (editable)

class ViewCounter {
    static long addViews(long current, long delta) {
        int next = (int) current + (int) delta;
        return next;
    }
}

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.