In the Sunan of At-Tirmidhi, Abu-Dawud and Musnad of Imam Ahmad, our Master, Muhammad bin Abdullah (Peace and blessings of Allaah be upon him) said:
"The first thing created by Allaah was the pen, then, He ordered it to write, so it wrote everything that will happen till the Day of Judgement."
This happened fifty thousand years before the creation of the heavens and the earth according to the Hadith on the strength of Abdullah bin 'Amr bin Al-'As recorded by Imam Ahmad in his Musnad.
When we realize this we will be the happiest people on earth. That, whatever unfolds in our lives at every moment is something already decided by Allaah aforetime and it has to follow that pattern.
Here this out! Allaah says in Surah Al-Hadid Q57v22-23
"No calamity occurs in the earth nor in yourselves but it is inscribed in the Book of Decrees before We bring in into existence. Verily, that is easy for Allaah."
In order that you may not grieve over the things that you fail to get, nor rejoice over that which has been given to you. Allaah likes not prideful boasters."
Know that whatever has missed you was never ordained by Allaah to reach you and that which reaches was never ordained by Allaah to miss you.
Hence, your failure to achieve your goals in life after exerting an appreciable effort should not and must not grieve you.
Likewise, your material accomplishments and spiritual heights should not and must not cause you to be arrogant and proud because they were not given to you except that Allaah has decided so.
A Muslim makes peace with the decisions of Allaah and he's fully aware that at every moment, Allaah executes His Decisions in the Entire universe.
Do not be sad.
Do not be suicidal.
Do not be proud.
Do not be arrogant.
Know that whatever Allaah decides, happens.