How to reconstruct the order book from a stock market data API’s incremental depth update messages?

At first glance, this sounds like one of those things that should be simple. Feed comes in, book gets built, done. Not quite. In practice, reconstructing an ord