^ This plus keep in mind that you don't have to build heavy industry first. You can, at a minor cost, just import all the stuff you need to maintain your battlestations, patrol stations and - as a last resort - ground batteries. So just build your defenses first and only worry about feeding them yourself second.
One thing that I've noticed when doing system defense is that one planet with a military HQ or better (level 2 and 3, which does take an industry slot, so use sparringly) is a lot more effective that just spamming little structure-slot system patrol stations everywhere (level 1). Which is to say that rather than sending out a dozen lag-inducing shrimp patrols that just get crewed up and spit out, you'll more likely end up with just one big doomstack that can actually kick some serious butt for you while you're out of town.
I've never seen a pirate raid get past a battlestation, no matter how big their armada. Though that is going to set you back 750,000cr... still, even your basic level 1 station is better for stopping pirate raids than ground defenses, in my experience. In fact, with enough starbases and large patrols then you won't even need ground batteries at all because no one will be able to land troops in the first place.