Around when I was writing a recent post on production vs. consumption cities, I also happened to be reading a short blurb about the history of Madrid. Madrid is like the original DC or Brasilia--no real commercial or logistical reason for existence, but rather planned as a geographically central capital for the newly united Spanish Kingdom starting in the 1600s or so (the royalty also liked the mild, sunny climate and the good hunting grounds). Even when the monarchy vacillated about whether Madrid should be the permanent capital or one of a few temporary capitals, the city kept growing, drawing in merchants and other service workers catering to the nobles that were increasingly clustering near this new power center.
So in this sense, Madrid is like an early version of a Lagos or Conakry. In fact, an oft-repeated quip is that the most abundant culinary "port" in Spain is Madrid, where a majority of the country's seafood is consumed despite its being located a few hundred miles inland of any coast.
I have loved Madrid ever since I spent a few years living there in my early 20s, strolling its quirky streets and absorbing its unique character. But even back then I vaguely realized that part of its character was this sense of having sprung out of nothing a few hundred years ago, and persisting as a population center, with entire regional, quasi-ethnic identities around long-established neighborhoods (think the Cockney culture of East London, an entirely urban regional cultural group) that had no underlying industrial reason to exist. So again, this characterization of consumption vs. production cities has proven useful for me.