
Four Bugs That Would Break a Matching Engine in Production
MatchEngine is an open-source order matching engine written in Go. After the initial release, we opened issues for every defect we could find through code review. This article covers the four bugs we fixed in v0.2.0, why each one matters, and the exact code changes that resolved them. These are not exotic edge cases. They are the kind of bugs that survive code review, pass unit tests, and then blow up under real traffic. Bug #1: Duplicate Order IDs Corrupt the Book The Problem The engine accepted any order ID provided by the caller. There was no uniqueness check. Submitting two orders with the same ID caused both to exist in the book: e . SubmitOrder ( "BTC" , model . NewLimitOrder ( "dup" , model . Sell , d ( "100" ), d ( "5" ))) e . SubmitOrder ( "BTC" , model . NewLimitOrder ( "dup" , model . Sell , d ( "200" ), d ( "10" ))) // Both orders now live in the book with ID "dup" When CancelOrder("BTC", "dup") was called, the old RemoveOrder did a linear scan and stopped at the first matc
Continue reading on Dev.to
Opens in a new tab

