There is no one answer to the question you are asking, it is dependent on the type of checkout process you are creating (Local or Remote) and the gateway you are using.
lets take PayPal as an example.
If you are using Local Chekout:
The PayPal local checkout behavior on the confirm page will automatically transfer the user to the failure page if the transaction fails. If it is successful, the order will be stored and the email sent then the page is directed to the success page.
It is really not necessary to wait till the success page to send the email or store the order in the database since the confirm page will not get to the code to perform those action unless the order is successful.
If you use Remote checkout however, the checkout success page really only means that paypal has agreed to process the transaction.
The transaction is placed in a queue and will be processed on a first come first served basis with the bank. It may be processed in 5 minutes, or as long as 5 day's.
With paypal standard checkout, you need to configure your account to use an IPN page. Once the transaction is processed through the gateway, paypal will post the results through the IPN page. on the IPN -page, you can add the behaviors for sending the email and storing the order in the database.