World: The world is 1/4th the diameter of Earth, and there are 2 continents + the poles, like our poles. Esia, 25% of the size of real-life Asia, and Aurope, 25% of the size of real-life Europe. Their is less ocean proportionally than our world and the gravity is Earth-like with the planet inhabited by humans.
Kingdom X, back from last question, has constructed the largest series of fortifications ever. Consider Asia as an oval 2000km by 1000km (tell me if my land sizes are unrealistic). Kingdom X is bordered by the ocean, and has a natural mountain range (considered impassable) with a continuous gap around 700km long.
This Gap is 200km and is a large seath of flat terrain. It is uncolonized similar to the Korean DMZ due to border disputes. There are several trading towns on either side of the gap including Kingdom Y, but the Advent of railroads means that their population is small and inufficent to stage an army from.
The population of Kingdom X is 30 million people, with a defense millita of around 20,000 (don't want the peasants to revolt now). Around 20% of the population are magicians. Kingdom X needs to defend against 50,000 people once every 6 months and 100,000 every few years. Assume that these armies only start once the defense sufficiently impedes smaller armies.
Magicians in this world replace cannons and guns (simply no need). Training time is around 4 years from childhood, and fireballs 1 feet in diameter can be thrown once a minute for an hour, or more per minute for less total time. Resting time is about a day. Magicians can also shoot lightning, but I don't forsee that chaning much. Calvary and chariots are widespread, and so are crossbows.
Technology is still early-steam with feudal elements, including steam trains (around 150kph?) and industry based around steam engines. Iron and steel are widespread, and all countries in Esia have access to this technology. Messages are still delivered by magic pigeon, who can fly 200kph and don't tire.
The walls will be built for 1500 years, with the lots of reinforcement in the last 300 years due to increased tensions and steam power for the last 200. We'll also say the populace generally approves of these defensive measures, keeping morale decently high.
I was thinking of building a large stone wall similar to the Chinese Great Wall, but the consequences of having a limited supply of troops (only 40 per km) really hinders progress. On the other hand, fireballs could easily destroy siege towers, and with an effective steam railroad, reinforcements could be shipped in quickly.
I guess the final question is: Could a China-style wall with a railroad for transport and magic be effective repelling against armies 5 times the militias size? If no, what option would be effective?
A side note, technologies using steam not mentioned can be used by both sides if reasonable. I personally feel that defense will be easy with a steam railroad, but I'm not sure if I'm overestimating the capacity of trains.