A good defence tactic discourages attackers before they even attack, and makes it harder for them to destroy the town or get ressources if they attack.
When setting up your town consider the route that will most likely be used by an attacker. Also it is vital to take into consideration the type of attack that is most likely to occur and the offence used. A common mistake is the tendency to place key defence mechanisms too close together. This allows Spartacus to destroy many key defence buildings before setting out attack forces. Also all too often players fail to make good use of bombs and spike traps. These should be set out in the most likely line of attack so as to catch out the attackers where possible.
Where possible protect your town hall and gold and warehouses. These are the main reason that you are being attacked. Set these to the centre of the village and surround them with the defence forces so that it takes the enemy as long as possible to they reach your resources.
Catapults are easy to destroy but very effective as a defence tool. Place these close to the centre of the town and make sure that there is ample space between each of them so that you give them the best chance of survival.
Walls are an important strategic element. They decide how attacking troops will find their way through the city, especially for melee troops. Upgrading all walls is expensive, but a town with no or weak walls is easy to defeat, especially with fast troops like thieves.