The mempool, fee estimation, and replace-by-fee
Every unconfirmed transaction waits in a pool on each node called the mempool until a miner includes it in a block. Because block space is limited and miners are economically motivated to maximize the fees they collect, transactions offering a higher fee per byte generally get confirmed sooner. Fees fluctuate with demand: when many people are trying to transact at once, the mempool fills up and users have to bid higher fees to get prioritized, and when demand is low, even low-fee transactions confirm quickly. Wallets estimate a reasonable fee by looking at the current mempool and recent block history to guess what fee rate is likely to get confirmed within a target number of blocks.
Sometimes a transaction is sent with too low a fee and gets stuck. Replace-by-fee, or RBF, is a feature that lets the sender rebroadcast the same transaction with a higher fee before it confirms, replacing the original in the mempool. It's opt-in and signaled at the time the transaction is created, and it exists specifically so users aren't forced to wait indefinitely or pay for a second, conflicting transaction just because they underestimated the fee.
