This is a quote from the book "On Zero Confirmation Transactions" by Chris Pacia
...s the legitimate transaction first and the double spend second (or preferably not at all), while ensuring the mining pools see the double spend first and the legitimate transaction second. Given how fast transactions propagate around the network, it’s tricky to get the timing correct, but assuming you do, the merchant will think he received a valid payment, while the miners will incl ude double spend in their blocks. This can be done with a very high success rate and is probably responsible for almost all of the ‘zero confirmations transactions are trivially reversed’ me...
read full book block explorer