Since I didn't see a post about this, unless I overlooked it, I thought it worth mentioning a few points on defense.
First and foremost, appoint your highest attack hero as mayor. This will ensure that he is not captured. This is also crucial if you are anticipating an attack and not online. As long as that hero is mayor, he will not abandon your city. High attack heroes are crucial to keep.
As covered in the building guide, having 15k-17k Archer towers is important, equally important is having 1k+ traps, I prefer 2k. Since battle runs its course through rounds, the more stops you cause your enemy, the greater your advantage. In the unfortunate event that your defenses are crushed, leaving you with only a mediced force and incoming reinforcements, having 1 single trap on your defensive front can mean the difference between win or loss. This is especially crucial if you are receiving reinforcements, saving your allies troops and prolonging the life of your own city. It can benefit the defender to leave 25 open spaces on walls to queue traps during an incoming attack(traps will always need to be replaced after a hit); if your defenses are wiped out and reinforcements are on the way, fill your wall queue with a small amount of traps, abalists and towers, even rolling logs if you have the resources and time:
5 traps - 2 abalists - 1 tower - 5 traps - 2 abalists - 1 tower and so on, keep it filled.
This will slow the enemies waves down to give defending archers extra rounds to score hits. It can also be a good idea to keep producing small amounts of pikemen and swordsmen if you are only receiving archers as reinforcements. This again, will add extra stops to the enemies' battle progression. Remember to pay mind to the enemy movement that your beacon tower provides. Queue as many a variety of defenses within the time of strike, with multiple waves, keep with small amounts to keep refreshing defenses for as many waves as possible. Avoid training cavalry/cataphracts for this cause. They are too expensive, take too long to train and are too fast to run into battle then die in the first round. Horses are bad for defense, send them to another city, or a valley close by.
To add to this, if you are sure you are going to lose a battle and you have many resources to spend, queue up as many troops in 1 single barracks to eat up as many resources as you can, after the attack lands, cancel the production to reclaim a percentage of the spent resources. This lowers your enemy's gains and gives you enough resources to continue building defenses.
As mentioned in the attacking guide, scout bombs are more effective vs gates open than closed. Leaving gates open can result in 13k-18k loss of archers. If you can snap the gates closed before they hit, you're looking at losing about 500 archer towers and a few traps. As far as cost of resources is concerned, 500 towers is 1mil lumber and 250k iron. 15k archers is 5.25mil lumber and 4.5mil iron. With regards to the battle at hand, losing towers is far less detrimental than losing archers. As mentioned above, your towers will still provide ample support in addition to adding the extra round against attackers, letting your archers score extra hits.
Hope this info is of help, but not needed. I've become quite accustomed lately to being under siege and using these tactics, I have been able to hold my ground.