If the System.ExtrinsicFailed event was emitted within a given extrinsic, does it mean that all other events that were also emitted within it can be considered invalid and should not be taken into account?
All dispatchables are executed in storage transactions and when the dispatchable returns an error, the storage transaction is thrown away. Events are stored in the storage as well. This means when your dispatchable returns an error, also the events send by this dispatchable are thrown away.
Example link: In extrinsic balances.transfer, the events balances.Withdraw and balances.Deposit were triggered, which indicate a change in the balance of two addresses. The system.ExtrinsicFailed event was also called which indicates that extrinsic failed. Should balance changes in this case be taken into account or should they be ignored?
The balance events you are seeing there are coming from the transaction payment signed extension. These operations are done on purpose outside of the dispatch of the actual as they are ensuring that your chain is not open to dos attacks. The sender should pay for each extrinsic that is applied on chain, even if the outcome is an error.