I see what you mean but they are still taking a decent amount of risk doing that. I often change/cancel my limit orders and if I change my order after they bought ahead of me, they are fully exposed to what they bought.
For example, if I put in a limit order at $230 and they buy when the price is $232 hoping they will just unload to me at $230, they are hoping I don't cancel that order.
I assume it averages out to where they still make money on it but they are still taking that risk.
They don’t buy at $232, they buy at $230.01. And this happens at a very short time scale.
It's even better than giving an opportunity of buying at $230.01: basically a retail customer placing a limit order of buying 100 shares for $230.00 gives middlemen the opportunity to go long 100 shares
between $230.00 and the current market price, with a guaranteed stop order at $230.00, for whatever order delay the customer is accepting.
For example if there's a big cluster of buy orders at $230.20 from institutional investors protecting an options strike price, the front running algo will have a few seconds of opportunity to place a buy limit order at $230.21 in the hope of a bounce from $231.20 - and worst case they'd get a guaranteed exit price of $230.00 from you. Without your buy limit order no such price guarantee exists: when breaking through resistance the price can and often will drop to $229.50 or lower without filling the algo's $230.00 exit price sell order.
So your "pending" order gives them a guaranteed exit price, which is
very valuable: half of the highly leveraged margin-trading HFT shops on Wall Street went bankrupt during the infamous "Flash Crash of 2010", because they underestimated that a "no guaranteed exit price" low liquidity event isn't a joke and might be 10% below the current price:
Few retail customers will question 1-2 seconds of delay after clicking "BUY", and I've seen retail platforms with 10+ second delays in "processing" new orders...
Even 1-2 seconds of delay is an eternity of opportunity in the HFT world: it's 1,000,000-2,000,000 nanoseconds.
Retail limit orders are particularly lucrative if your new limit order is just below the current market price and the price happens to drop below $230.00 in the 1-2 seconds after you placed the order (or shortly before it). In that case instant profits are guaranteed: they'll buy for $229.90 or $229.73, or whatever lowest price they manage to hit (via buy limit orders, so they never risk getting a higher than $229.99 price), and if they cannot get 100 shares in that 1-2 seconds time window they simply place your limit order in the NASDAQ order book and call it a day: "heads I win, tails you lose".
Note that "cancellation" or modification of your limit orders doesn't change any of this, in fact it
increases the opportunity to front-run your order: the primary time window is the few seconds between your click and the notification of your new, cancelled or updated order. The time window between you clicking and them actually performing a legally binding order on your behalf on the NASDAQ trading system (aggregated with other orders), which cannot be front-run anymore.
This all is possible because
technically the retail broker is not bound by SEC "best national price" regulations and guarantees until your order has been "processed" - and the SEC is very careful to not require brokers from having a fiduciary duty to get best possible order execution for clients.
Your own broker, or third parties your broker is selling your "retail flow" to are free to trade against you, using the temporary knowledge of your guaranteed purchase price of $230.00 of 100 shares.
Sometimes they'll also give a few crumbs back to you and give the shares for $230.01 and advertise it as a "price improvement", which also gives them plausible deniability for more egregious cases of front-running...
That blinking "order being verified" status feedback of your order? The weirdly slow placement of new orders, while we can do online gaming with <50 msec latencies that perform much more complex algorithms than simple order book management?
That delay is the sign of you getting scammed.