And if you don't want to waste that many tiles and tech time on it, you will find it very hard to repel invasions.
As long as you have Elerium to spare, it only takes two tiles to render a planet immune to conventional invasion and invasions supported by planetary bombardment; an Elerium Defense Shield and a Planetary Defense System which are adjacent to one another gives you 100% planetary defense (75% PD from the EDS + 10% PD from the PDS + 15% PD from the three levels on the PDS due to being adjacent to the EDS), and neither Conventional Warfare nor Planetary Bombardment reduce planetary defense. If you can get an extra level on the PDS from somewhere (for example, a bonus tile or a colony capital) and you choose the specialization following Militarization that gives +10% PD and research the first tech in the planetary defense branch for another +10% PD, you're also able to render planets of your choice immune to Information Warfare with only two tiles and an elerium invested into defenses (because you're at 125% PD and Information Warfare can only reduce that to 100%), and you can disable Biological Warfare with a single tech. For two tiles, an elerium, and a little bit of research, I can render planets immune to any invasion that isn't Tidal Disruption or Core Detonation, and I'm not even abusing the system yet by stacking up ridiculous numbers of levels onto a single improvement.
On top of that, this kind of setup will eventually render the worlds thus protected immune to all invasion types; Planetary Defense Systems upgrade to Planetary Defense Domes, and an EDS adjacent to a PDD will give your planet 140% PD. Get 10% more PD from one of the techs (and I'm fairly certain that you will have at least +10% PD to all planets in your empire from techs if you have PDDs), and you're looking at rendering a planet immune to all invasion types at the cost of 1 elerium and two tiles, plus a bit of time to build and upgrade the defenses.
While I would not do this on all worlds, this is a fairly trivial cost to render an important world immune to invasion. Especially since, at least for Conventional Warfare and Planetary Bombardment, it costs less research to obtain sufficiently powerful defenses to become immune than it takes to gain access to the invasions in the first place; all you need is Militarization, and Militarization is a prerequisite to all invasion options.
Of course, since a powerful space navy is roughly as effective at granting invasion immunity to my worlds and doesn't cost me tile slots, and since I'm generally able to field a better navy than my opponents or at least intercept the computer's transports, I'll generally go for a space-based invasion immunity over an improvement-based invasion immunity.
(Why am I not counting the level bonus on the EDS when I gave PD numbers? Because the EDS's level bonus doesn't seem to work; if it did, though, you wouldn't need the extra level on the PDS to get immunity to information warfare via improvements and +PD techs, and you wouldn't need any +PD techs at all to get total invasion immunity when pairing an EDS and a PDD. Of course, as the level bonus for the EDS defined to be an empire-wide bonus in ImprovementDefs, I'm not at all certain that it's a bad thing that the level bonus doesn't work; if it did work, it'd be trivially easy to get empire-wide invasion immunity with just a handful of elerium.)