If a fly is bothering you, can one kill it? Is it zaar baalei chaim?
I also heard that if someone kills a spider it is a mitzvah because spiders made spider webs so that the bais hamikdash should burn longer? If so where is the source?
It is permitted to kill bugs if they disturb you, and this is not considered tzaar baalei chayim (just as it is permitted to kill animals to eat them).
Concerning spiders: On the one hand, Chazal write that King David was saved by a spider’s web, which caused Shaul to believe that he was not in the cave. On the other, it is related that spiders brought fire to the Mikdash.
I have not seen that there is a special mitzvah to kill spiders, and they should be treated like other insects. If they don’t disturb, leave them alone. If they disturb, move them away, and if necessary kill them.