My way of defense is a more of an 'offensive defense' that I start planning during the colonization phase. Try not to expand in a straight line, as more often then not, it will leave most of your planets open to attack. If you expand around your homeplanet, there will often be less planets to defend.(say there are three planets one jump away, you colonize them all, you will only have to defend those three, instead of four). This is even better if one or more of your planets only have one jumplane for you can hopefully colonize that gravity well leaving you with another planet under your belt without another one to defend. Once you have enough planets/enough to defend.
With that, all you have to do it fortify the frontline with defences (missile turrets in my case

) and some ships. That way, you can push yourself forward if needed without losing much defence (take one of the frontline planet's defence, move it forward and attack the next grav well). I haven't been able to play long enough to get to the gate tech. With that, you should be able to have gates at all the frontline planets allowing you to have one defense fleet (maybe two incase of a two prong attack).
BUUUUUT! I am still just a complete noob at this game, and I have no idea if this would be any good online.