I usually (if possible) use mountain ranges as walls, and just wall of the gaps. Same goes for plateaus and oceans. With a bunch of sentry towers behind the walls. I can shoot attackers to pieces while they try to break through. Then, by the time they do, I’ve moved all available soldiers to where they are.