The Exchange That Could Not List Itself

Medium

· Backend

Incident

SEV-1

BUG-BATS-IPO

Priority: P0 · reported by market operations

Time to fix: 20 min

Failing checks on the shipped build

  • a symbol on a lower bound belongs to that row

    expected "U2" but got "U1"

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

BATS Global Markets · 2012

Modelled on BATS Global Markets' own IPO (23 March 2012): BATS listed its shares on its own exchange, and on the day a software bug affected trading in symbols in the range from A to BFZZZ — a range that included the BATS ticker itself. The company withdrew the IPO the same day.

BATS did not publish the faulty code; this project is a reconstruction of a range-routing mistake of that kind. router.js sends a symbol to the matching unit that owns its alphabetical range, but it scans the table with the wrong comparison and never checks the upper bound.

Fix route so every symbol reaches exactly the unit whose range contains it.

Code map

// Sends each symbol to the matching unit that owns its range.
exports.route = function (table, symbol) {
  var s = String(symbol).toUpperCase();
  for (var i = table.length - 1; i >= 0; i--) {
    if (s > table[i].lo) return table[i].unit;
  }
  return null;
};

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.

The Exchange That Could Not List Itself — Bug Hunt

Modelled on BATS Global Markets' own IPO (23 March 2012): BATS listed its shares on its own exchange, and on the day a software bug affected trading in…

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Parsing, Validation
  • Modelled on: BATS Global Markets · 2012
  • Visible tests: ordinary symbols reach their unit; a symbol on a lower bound belongs to that row
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: P0)
  • Ticket: BUG-BATS-IPO
  • Reported by: market operations
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • a symbol on a lower bound belongs to that row — expected "U2" but got "U1"

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

Modelled on BATS Global Markets' own IPO (23 March 2012): BATS listed its shares on its own exchange, and on the day a software bug affected trading in symbols in the range from A to BFZZZ — a range that included the BATS ticker itself. The company withdrew the IPO the same day.

BATS did not publish the faulty code; this project is a reconstruction of a range-routing mistake of that kind. router.js sends a symbol to the matching unit that owns its alphabetical range, but it scans the table with the wrong comparison and never checks the upper bound.

Fix route so every symbol reaches exactly the unit whose range contains it.

Bug report

BUG-BATS-IPO · Priority: P0 · Reported by: market operations

route(table, symbol) — table rows are { lo, hi, unit }, both bounds INCLUSIVE:

  • the symbol is compared upper-cased, as a plain string
  • return the unit of the row with lo <= symbol <= hi
  • a symbol on a boundary belongs to the row that names it ("BG" -> the row whose lo is "BG"; "A" -> the row whose lo is "A")
  • a symbol that falls in no row returns null — never a neighbouring unit

Observed: symbols equal to a range's lower bound went to the wrong unit (or nowhere), and symbols in an unassigned gap were routed anyway.

Logs

[router] BG -> U1 (expected U2)
[router] A -> null

The code as shipped

src/exchange/router.js (editable)

// Sends each symbol to the matching unit that owns its range.
exports.route = function (table, symbol) {
  var s = String(symbol).toUpperCase();
  for (var i = table.length - 1; i >= 0; i--) {
    if (s > table[i].lo) return table[i].unit;
  }
  return null;
};

Read-only context: src/exchange/partitions.js.

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 JavaScript bug hunts.