Throughout history, Shānxī has flip-flopped from China’s defensive bulwark to a springboard for invaders descending upon the fertile north China plain. The Tuoba were the first outsiders to set up camp here, instating Dàtóng as their capital during the northern Wei (AD 386–534). Eventual assimilation and intermarriage with powerful Han Chinese clans resulted in a new line of aristocratic families, who went on to play an important role in the Sui and Tang dynasty courts. As China weakened following the collapse of the Tang, northern invaders moved back into Shānxī, most notably the Khitan (907–1125), whose western capital was again based in Dàtóng.
After the Ming regained control of northern China, Shānxī was developed anew as a defensive outpost, with an inner and outer Great Wall constructed along the northern boundaries for enforced protection. Local merchants (known as Jìn shāng) took advantage of the military development to do a brisk business in trade, eventually transforming the province into the country’s financial centre during the Qing dynasty.