Replacing an unconfirmed transaction with a different transaction that pays a higher transaction fee is known as RBF.
This is done to primarily replace an old unconfirmed transaction with low transaction fees that is lying in the Bitcoin mempool for some time and is not getting picked by miners.
Consider the following example:
Maria sends 1 BTC to Bob with 0.0001 BTC as fees because it was not a priority for Maria and Bob wasn’t in a hurry to receive his payment.
But hours passed by and later Bob started demanding his BTC because he wanted to use it to complete other transactions.
Seeing the delay and understanding how bitcoin transactions work, Maria decided to issue a new transaction with the same output to the same address but with a higher transaction fee (i.e. through Replace By Fee).
The transaction then gets noticed by miners and is picked up in a block because the transaction fee makes financial sense according to the market standards.
In the previous example, RBF is used to “accelerate” the confirmation of the transaction. However, RBF can be used for other purposes.
What are the risks?
Let's consider the previous example with a slight difference:
Maria is going to purchase some items from Bob so she sends him 1 BTC with 0.0001 BTC as fees.
After a couple of minutes Maria changes her mind and wants her money back, so as the transaction is still unconfirmed, she decides to replace the original transaction with a new one with a higher fee that sends the funds back to her wallet.
In the meantime, Bob has already shipped the items to Maria’s address.
In this sad case, Maria will get her items, but Bob will not get his funds.
How do I protect myself from fraud?
RBF can lead to fraud and double spending problems if not used properly which is why the receiver of the bitcoins needs to make sure if a transaction in question is already generated with RBF.
On the BitPay app an RBF unconfirmed transaction will be shown in a pink-ish color:
If you tap the transaction in pink, you will see the following message:
In conclusion, if you notice this feature is ON (pink coloured transaction) then you need to wait until the transaction gets one confirmation before considering it a successful transaction.