Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Postmortems

How one bad software update lost $460 million in 45 minutes

A real deploy gone wrong: an old flag, one forgotten server and no off button. What the SEC report says, and what to do differently.

Derpx0613 Nov · 5 min read
Contents
How bad was the damage?Step 1: why did an old flag come back to life?Step 2: how did one server get left out?Step 3: what was the hidden bug in the old code?Step 4: did anyone see the warnings?Step 5: why couldn't they just stop it?So what would I do differently?Sources
0% read · 5 min leftBack to top ↑
On this page0%
Contents
How bad was the damage?Step 1: why did an old flag come back to life?Step 2: how did one server get left out?Step 3: what was the hidden bug in the old code?Step 4: did anyone see the warnings?Step 5: why couldn't they just stop it?So what would I do differently?Sources

212 small orders went in. Over 4 million trades came out. About 45 minutes later, a trading firm had lost more than $460 million, with no hacker and no crash. Just a normal morning deploy.

That was Knight Capital on 1 August 2012. Knight bought and sold shares for other people, using software. The US market regulator, the SEC, wrote a long official order about it in 2013. I read it, and it teaches deploying code better than most tutorials.

Let's see how it happened, one step at a time.

How bad was the damage?

The SEC reports that Knight's router (the program that sends orders to the stock market) received just 212 small orders from customers. It turned them into millions of orders, which led to over 4 million trades in 154 stocks, for more than 397 million shares. All in about 45 minutes.

Bought too much3.5 B$
Sold too much3.15 B$
Final loss0.46 B$
In billions of dollars, as stated by the SEC. Bought and sold are the positions Knight was stuck holding. The loss is 'over 460 million'.

The SEC's wording is "lost over 460million".Somenewsstoriesgiveabout460 million". Some news stories give about 460million".Somenewsstoriesgiveabout440 million. I'm using the SEC's number.

So the loss was huge. But what actually went wrong in the code?

Step 1: why did an old flag come back to life?

Knight was adding support for a new stock exchange program. The new code was meant to replace some old, unused code called Power Peg. Power Peg had been switched off for many years, but it was still sitting in the program.

Here is the sneaky part. The new feature reused the same flag (a flag is just an on/off switch in the code) that used to turn Power Peg on.

Like relabelling a switch

Imagine a wall switch that used to turn on an old heater. You remove the heater, put a new label on the switch, and now it turns on a fan. It works, until someone visits a room where the old heater is still plugged in.

Why this matters: a flag with two meanings is a trap waiting for one wrong machine. So was there one?

Step 2: how did one server get left out?

The router ran on eight servers (computers). The SEC reports that a technician did not copy the new code to one of them. No second person checked the deployment, and Knight had no written rule that required it.

Servers 1 to 77 servers: new code, flag means the new feature
→
Server 81 server: old code, same flag wakes up Power Peg
Same signal, two meanings.

Imagine telling 7 of 8 team members that a meeting moved to Tuesday. The eighth shows up on Monday. Here, the eighth server also starts spending money.

Next question: why did the old code on server 8 go wild instead of just doing nothing?

Step 3: what was the hidden bug in the old code?

When Power Peg was alive, it counted how many shares were already bought and stopped when the order was done. In 2005 Knight moved that counter elsewhere in the code. The SEC reports they never retested Power Peg after that.

So on server 8, the old code had lost its "stop" counter. It kept sending orders again and again, even though the orders were already filled.

Click Next and follow one customer order through the system. Watch which node lights up at step 3.

Customer order
Servers 1 to 7
Server 8
Stock market

A small order arrives carrying the flag

Step 1 of 5
A simplified view of the SEC's account. The real system had more parts.

Did you see step 5? The loop has no exit. That is how 212 orders became millions.

Step 4: did anyone see the warnings?

Before the market even opened, Knight's system sent 97 automated emails with an error message reading "Power Peg disabled". The SEC reports these weren't designed as alerts, and people generally did not read them.

It is like an inbox with 400 unread messages, where the one that mattered was buried inside. So the warning existed. What about stopping it?

Step 5: why couldn't they just stop it?

Once the trades started, Knight had no quick way to stop. The SEC reports that Knight had no procedures to halt the router "in response to its own aberrant activity". Their monitoring tool needed a human to watch it and did not stop orders by itself.

Then the team tried a fix: they uninstalled the new code from the seven good servers. The SEC reports this made it worse, because now those servers could also wake up Power Peg.

  1. Orders pile up. Humans notice, but nothing stops the router.
  2. The team looks for the cause while the router keeps going.
  3. They remove the new code from the seven good servers.
  4. Now eight servers run the broken path, and the problem grows.

So what should a normal team copy from this?

So what would I do differently?

The SEC fined Knight $12 million (and ordered an outside review of its controls). But the better question is for us.

What would have helped
  • A second person (or a script) checking every server got the same version.
  • Deleting dead code, not leaving it asleep.
  • A new flag for a new feature, never a reused one.
  • An automatic stop: one button, or a rule, that halts the system when it behaves strangely. (That's my own plain-language term. The SEC's point was that Knight had no procedure to halt the router.)
  • A rollback plan that you practise, so you don't improvise in the middle of an incident.
What went wrong
  • One missed server and no review.
  • Old code that was never retested.
  • 97 emails treated as noise.
  • No automatic stop.
  • A rollback that made things worse.

You can try the small version on a side project. Add a feature flag, deploy to one test server, then check a dashboard before you roll it out everywhere. And ask yourself the Knight question: if this goes wrong right now, which button do I press?

Key takeaways
  • Reusing an old flag for a new meaning is a trap. Make a new one and delete the old code.
  • After a deploy, check that every server really runs the same version.
  • Alerts only help if someone reads them. Make the important ones loud.
  • Plan an automatic stop and a tested rollback before you need them. A bad rollback can be worse than the bug.

Sources

  • SEC — Order Instituting Administrative and Cease-and-Desist Proceedings, Knight Capital Americas LLC, Release No. 70694, 16 October 2013
  • SEC — Press release 2013-222
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Foundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)Distributed Systems · 6 minHow does your computer know the time? (And why it can be wrong)
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)