Learn the attacking game mechanics and use them to your own advantage. I would personally suggest to focus on getting to the Medieval Age as fast as possible to have more defensive buildings available and build them first and only afterwards upgrade them. Have in mind that towers that are under upgrade will not work if you get attacked so try to time these upgrades when you have a peace treaty (also have in mind when attacking other players – all the towers that are being upgraded will not harm you.)