1) if your attacker is sending few units at each flank, say 100 at each, then you should probably split your defense evenly between each (33-33-33). In case of larger numbers it is best to split your defenses between the left and right flank (50-0-50) because you will be in danger of receiving the -30% in the keep. If your tools or walls are not up to scratch and your attacker is using premium ruby tools it may even be best to go all on the left or right flank (100-0-0) so you can at least face your attacker in the courtyard on a level playing field.
2) firstly, type of unit. It is worth bearing in mind that the numbers you see incoming are not completely accurate so will differ from the numbers you see in the battle report even with a level 2 watchtower. If your attacker is sending a larger number of one type of units then make sure you change your set up. Melee defenders should be used against melee attackers and ranged defenders should be used against ranged attackers. if they are sending 50/50 ranged/melee then have 50/50 ranged melee. If they are going 70/30 then go 70/30.
The strength of the attacking unit is also important as travelling knights will cause a good deal more damage than heavy blue attackers (heavy crossbow and two-handed swordsmen). If you're lucky enough to be attacked by normal macemen and crossbowmen then relax and set up your attack so you meet them on each flank being attacked. The point is that the stronger the unit the more cautious should be and the more defenders/ruby tools you'll need- possibly an incoming of all travelling knights with ruby tools should be met on a single left or right flank.
3) going to have to split advice here for players using ruby tools and players using resource tools.
RESOURCE TOOLS-
If your attacker is using premium ruby tools then don't defend on all three flanks. If they are sending large number as well then only defend left or right flank and make sure you have enough defenders in your keep (roughly the amount you're being attacked with will be safe) to win in the courtyard.
If your attacker is using resource tools then set up your defenses normally (follow advice below)
RUBY TOOLS-
If your attacker is using ruby tools (and has decent-max number) then most the time set up 50-0-50. This will mean you'll win on the flanks and then you'll get the +30% courtyard bonus to defeat the units who came at the front gate. If the attack has lots of premium ruby tools then it is possible you could lose on the left and right flank set up like this especially if they are using travelling knights or you don't have level 4 towers and fully expanded walls. In which case it would be safe (although maybe no necessary) to set up 100-0-0.
4) type here refers to wall tools, gate tools, ranged tools and moat tools. If your attacker is missing any of these on a flank then they will have a considerable disadvantage which you should exploit as much as possible. If they don't include moat tools and you have a fire moat or even wooden steaks then you have a triply/doubly effective defense and can therefore spread your defense more across your walls.
5) not many towers or low level towers means less defenders on your walls and this means a reduced ability to defend large attacks. In this case probably best to set up 100-0-0.
There are many factors which effect the outcome of defensive battle and you must take all the points mentioned into account. It is very hard to write a guide on defending she each incoming varies so much and people's defenses vary so much not just between players but also between worlds, outposts and even villages. Thats why you've got to take this guide and apply the principles as best you can for the best success.
Most important things to consider are TOOLS and COURTYARD BONUS. Whatever your defense is like and whatever your attacker has sent to you, these are the things you should be considering most when setting up.