A high rate of gun ownership among the population might deter an invader or at least drive up the cost significantly if you know that on every street behind every window could be a granny with a rifle.
This is a given for decentralisation to work. Relying on centralised security whether that is police or military leaves the people vulnerable. They don’t need to be well-trained militias, they just need to be well-armed enough that the MAD of any invader is sufficient deterrent that conflict is avoided in most scenarios.