Gas fees exist because there are real costs to running the blockchain. Miners spend a lot of money running their mining rigs in a Proof of Work consensus blockchain, and there are electrical/hardware costs associated with that. You have to pay miners enough to incentivize them to actually maintain the blockchain for you, and you want that incentive to be large enough that you have a truly distributed network of miners so that 1) nobody can 51% attack the network with invalid transactions, and 2) even if all of the US goes offline, the blockchain is fine.
The reason why these fees are proportional to computation (which is where the gas measurement comes from) is because it simply makes more sense. If your transaction takes more computational steps, it burns more electricity and consumes more resources from the network. You should pay for that, and the amount should be proportional to the work. These fees also deter attacks on the network with things like infinite loops. I becomes economically impossible to sustain a spam attack when miners have the choice to ignore your transaction because it's not paying enough for them.
If a transaction is included in the blockchain, it hasn't failed, and this is when you pay your gas fees. Failed transactions do not cost anything because they are never computed by the network. However, transactions that did not specify a high enough gas limit to complete the computation, had incorrect data, or were wrong in some other way do cost money because they still cost the network to process these "failed" transactions. You cannot use a global distributed network, mess up, and hope for a refund. It's just not fair to the people who did the work for you.
In the future, contracts should be written to be able to anticipate failure ahead of time and exit quickly so that the gas consumed is small. This will help save people money when they mess up their transaction, but won't hurt miners.
Clear and thorough explanation. Kudos to you!
Please correct me if im wrong. When gas limit is specified as 100 thousand and your transaction needs 1 you will pay the limit you have specified if your transaction fails. Unlike when it succeeds!? Why is that so?
The gas limit only specifies the max amount you're willing to pay. If the transaction gets mined, you only pay for the gas actually consumed. If it's mined, the transaction is technically successful (even if the results aren't what you wanted).
If it's not mined, then nobody did the computation, so nobody gets paid anything.