The Granary is one of the first buildings in the game, built in the City Center, and takes care of the city's early Housing needs. It is useful for any city, but it is especially so for cities which have no access to Fresh Water. In such cities, it should be either the first, or one of the first buildings constructed, in order to allow the city's Population to grow to any useful size.
Once farming really took off, someplace was needed to put that surplus grain to keep it safe from rats, insects, and other humans. The oldest granaries yet uncovered date back to the pre-pottery Neolithic period in the Jordan Valley, c. 9500 BC. In the Indus Valley, the oldest date to 6000 BC, and the Egyptians were storing surplus grain in “silo” pits as a hedge against poor harvests by this time as well. In East Asia, the Yangshao in China were building elevated granaries along the Yellow River around 5000 BC, and eventually the Koreans (c. 1000 BC) and the Japanese (c. 800 BC) figured it out as well. In modern times, granaries – like all else – have gotten larger, automated, and more complex; the rich farmlands of the United States and Russia, especially, are dotted with huge silos and grain elevators to help feed the teeming masses of civilization.