What’s for dinner? For that matter, what’s to eat, full stop? In a few decades time, that second question may become pressing. Mankind’s awareness of our food supplies has been heightened by massive crop failures due to millennial level floods, protracted droughts, and numerous food-borne disease outbreaks caused by microbes such as salmonella, E. coli strain 0157, toxoplasma and listeria. Consumers the world over now demand to know where their food comes from and how it is produced.

As if that were not enough to keep us up at all hours of the night, larger issues loom in the near future as our population continues to expand, placing greater pressure on the world’s agricultural industries to meet demands. As a species, we need to know whether modern farming is sustainable and compatible with the rest of the natural world, or is it causing irreparable damage to the environment that will eventually turn today’s serious problem of today into a food crisis of epic proportions in the near future?

To answer some of these questions, it’s important to recall how things got this way to begin with. In the beginning of the modern era of humankind, around 10,000 years ago, most of our earliest cities were located close to agricultural land. Cities needed crops.

In the Middle East, for example, einkorn wheat was first successfully cultivated around 11,000 years ago in the south-eastern part of what is now Turkey. Farming then rapidly spread through the whole of that region. It had many advantages, including the fact that when wheat yields exceeded demand, its grain could be stored without losing any nutritional value. These early cities – Ur, Nineveh, Jericho, Babylon – became established next to their farmland, and for a time flourished in concert with the fields that provided their sustenance. Yet despite the invention of farming, eventually all of these early cities fell into disrepair, their decaying fortified walls and crumbling buildings blending seamlessly back into the harsh, arid landscapes which gave rise to them. The cause? Desertification. Drier weather patterns caused the failure of this single crop their civilisation depended upon – a mono-crop dependent upon a constant source of water to survive. It was irrigation which allowed such large amounts of wheat to be grown – but falling water levels brought the Middle East’s first agricultural revolution to an end. Only Egypt survived in the long term, thanks to the Nile River.

Today’s cities are at risk from a different set of issues. If trends in urbanisation continue at their current rates, cities could evolve into places where intolerable numbers of people may have to live, and who are forced to live well below the poverty limit, threatening to overwhelm sanitation systems and housing. Food and drinking water would be even scarcer than in many of today’s developing cities.

But this doesn’t have to happen. Most urban centres are experiencing a re-birth of their direct connections to agriculture. Within just the past 10 years, an increasing interest in city farming has been paralleled by the creation of the slow food and locallly sourced, or "locavore" movements, a foundation for the rise of urban farming initiatives.

Bright lights, big city

Included in the mix of successful city-based agricultural projects are rooftop gardens, rooftop greenhouses (both low tech and hydroponic), above-ground planting beds, the use of empty lots as farmland, and vertical farms that occupy tall buildings and abandoned warehouses. Collectively, these examples show the validity of growing food in the city. Not only could be they be carried out efficiently – such as rooftop greenhouses giving much higher yields than outdoor farms – but they could also operate without the pollution associated with outdoor farming.

Already, we have large-scale indoor farms such as EuroFresh Farms in Willcox, Arizona (318 acres (1.3 square km) of one-storey-high hydroponic greenhouses), supplying fresh tomatoes and cucumbers, and FarmedHere in Bedford Park, Illinois, a 90,000 square-foot (8,360 square metre) empty warehouse several storeys tall that was converted into an indoor farm producing tilapia (freshwater fish), a variety of leafy green vegetables, and several value-added products. Indoor farms (controlled environment agriculture or CEA) will undoubtedly replace most outdoor urban agricultural initiatives as the advantages of farming within protected environments become more widely accepted.

Judging by current trends in the development of advanced technologies, city-based CEA appears to have a bright future, as newer strategies emerge enabling indoor farming to be carried with increasing efficiency. Grow lights, for instance, have evolved from ordinary fluorescent light fixtures – expensive to operate – into a series of light-emitting diode (LED) lighting schemes. These LED lights can be adapted to emit light spectra at two dominant wavelengths (red 680nm; blue 460nm) tailored for growing green plants. The benefits of LED grow lights are obvious when compared to other outdated lighting schemes: LEDs cost less to run, and produce greater yields of most commercial crops, such as leafy greens and tomatoes. In early 2013, Phillips in the Netherlands announced it had invented an LED light with energy efficiency 150% greater than existing LED grow lights. This new development promises to significantly reduce energy costs involved in growing such crops.

Although most current vertical farming operations have chosen to specialise in cash crops consisting of leafy green vegetables (easy to grow and much in demand), in the near future, consumers are likely to ask for a wider variety of vegetables and fruits grown without pesticides, herbicides and other harmful chemical contaminants. At that point, vertical farming in tall buildings will replace less productive single-story greenhouses as the source of all city-grown produce. Some form of vertical farming now exists in Japan, Korea, Singapore, the United States, and Canada. New vertical farms are planned for a number of cities in the United States (Milwaukee, Memphis and Jackson Hole in Wyoming), and Linköping, Sweden.

Urban agriculture has the potential to become so pervasive within our cities that by the year 2050 they may be able to provide its citizens with up to 50% of the food they consume. In doing so, ecosystems that were fragmented in favour of farmland could be allowed to regain most of their ecological functions, creating a much healthier planet for all creatures great and small.

For more in our Building Tomorrow series, click here. If you would like to comment on this story or anything else you have seen on Future, head over to our Facebook page or message us on Twitter.