Two Swaps Walk Into a Block
You hit confirm on a Uniswap v3 swap. Somewhere else, at almost the same millisecond, someone else hits confirm on the same pool, the same pair. One of you goes first. The other trades against a pool that has already moved. That gap between those two outcomes is not random, not a glitch, and absolutely not neutral. It has a price, and somebody is paying it whether they know it or not.
This is the mechanics of intra-block transaction ordering on decentralized exchanges. Most DeFi guides either skip it entirely or dissolve into vague warnings about "slippage." We can do better.
The Block Is a Queue, and the Queue Is for Sale
A blockchain block is an ordered list of transactions. Order matters enormously on a DEX because every swap changes the pool's state, and the second swap in a sequence operates on a pool that the first swap already moved.
The mechanism that determines order is the priority fee (called a gas tip on Ethereum post-EIP-1559). Validators and block producers sort pending transactions from the mempool by fee paid per unit of gas. Higher tip, earlier slot. It's an auction, run implicitly, every twelve seconds on Ethereum.
The wrinkle: this creates a direct financial incentive to watch the mempool and react to other people's transactions before they confirm. That practice has a name. Maximal Extractable Value, or MEV.
A Worked Example: The $8,000 Difference
Suppose Alice and Bob both spot an arbitrage opportunity in an ETH/USDC pool on a major DEX. The pool is slightly mispriced relative to a centralized exchange. Alice submits her swap at 8:00:01 PM with a standard priority fee. Bob submits his at 8:00:02 PM with a priority fee three times higher.
Both transactions land in the same block. The block producer sees both, ranks by fee, and Bob gets slot one. He executes at the favorable price, moves the pool, captures the arbitrage. Alice executes second, against a pool that has already moved against her. Her swap goes through (her slippage tolerance allowed it) but she paid the spread.
Now add a third actor: a searcher running automated MEV bots. The searcher sees Alice's transaction in the public mempool, calculates the price impact, and inserts their own transaction ahead of her, buying before her trade and selling immediately after. This is the classic sandwich attack. Alice's transaction ends up in the middle of a three-transaction sequence she never agreed to, and the searcher extracted value from the price movement Alice's own trade created.
The dollar figures on a real sandwich range from a few cents on a small swap to thousands on a large one. Researchers at Flashbots documented hundreds of millions of dollars in extracted MEV across Ethereum in the years following DeFi's expansion, with sandwiching among the most common vectors.
What Protocols Actually Do About It
This is the part that separates a real explainer from a fear piece.
Slippage tolerance as a blunt instrument. Every DEX interface lets you set a maximum acceptable price deviation, typically 0.5% to 1% for stable pairs, higher for volatile ones. If the executed price falls outside that range, the transaction reverts. It protects against catastrophic outcomes but won't stop a sandwich calibrated to fit within the tolerance window. A seatbelt, not a collision-avoidance system.
Private mempools and RPC endpoints. Services like Flashbots Protect and MEV Blocker route your transaction directly to block builders without exposing it to the public mempool first. No public visibility means searchers can't front-run or sandwich what they can't see. The tradeoff is mild: slightly longer confirmation times in some cases, and a dependency on the specific builder relationships the service maintains. Still, for anyone doing swaps above a few hundred dollars regularly, using a private RPC is one of the simplest and most underrated defensive moves available. Most people have never heard of it.
AMM design changes. Uniswap v3's concentrated liquidity doesn't directly solve ordering conflicts, but protocols like CoW Protocol use batch auctions specifically to neutralize them. In a batch auction, all trades submitted within a time window settle simultaneously at a single clearing price rather than sequentially. If Alice and Bob both want to swap in the same batch, they get the same price. The ordering problem disappears because there is no ordering. The mechanism also enables peer-to-peer matching: if Alice wants to buy ETH and Bob wants to sell ETH within the same batch, CoW Protocol can match them directly, bypassing the AMM entirely and giving both a better price.
Commit-reveal schemes. Some protocols have experimented with requiring users to commit a hash of their transaction parameters before revealing the actual trade. This prevents searchers from knowing what's coming. The practical friction is real, though: two-step transactions are slower and more expensive in gas, which limits adoption.
What People Get Wrong
The common misconception is that MEV is purely parasitic and that the solution is to eliminate it. That framing is wrong, and it leads people toward bad conclusions.
Arbitrage, one major category of MEV, actually helps DEX users on net. When a pool's price drifts from the market rate, arbitrageurs correct it. Without them, liquidity providers would bleed value to uninformed traders and prices on DEXs would be stale and unreliable. The problem isn't that people profit from ordering. The problem is when that profit comes at a direct, hidden cost to a specific user's trade, as in sandwiching, rather than from genuine price correction.
Think of it like the difference between a freight broker who profits by finding a more efficient shipping route and a scalper who buys the last concert ticket before you reach the window and immediately sells it back at markup. Both are responding to price signals. Only one is taking something from you specifically.
And here is the thing most users miss: a slippage tolerance of 0.5% feels like protection, but a sandwich attack calibrated to fit within that window still extracts value. The attacker just clips a smaller margin. Setting slippage to 3% or higher on a volatile token without a private RPC leaves a larger opening than most users realize, and someone's bot is almost certainly aware of it.
The Ordering Problem Isn't Going Away
As long as blocks are ordered lists and ordering affects price, there will be economic pressure to control that order. The ecosystem has made genuine progress: private mempools reduce exposure, batch auctions eliminate sequential ordering for protocols that adopt them, and MEV research has become a serious academic and engineering discipline rather than a fringe concern.
The incentive structure, though, is baked into how blockchains work. Any sequenced system with state changes creates ordering value. The best defenses don't try to wish that away. They route around it, and the gap between users who know that and users who don't is measured in basis points, every single block.