Where was the space to house all of these people, and how was the massive population fed? Was there some kind of rice dole to feed the poor?
What was the infrastructure like?
*edit: doll to dole
I don't have the resources to answer most of your questions right now, but I can offer a beginning.
The thing you have to understand is that one very specific historical circumstance led to Edo's massive growth: the "alternating attendance system" (sankin kotai) enacted by the Tokugawa Shogunate. Basically, as a means of exerting social and economic control over the dozens of (often quite restive) feudal lords (daimyo) that constituted Japan's political structure - lords who I might add were in no way ideologically bound to the shogunate, a military dynasty with none of the "divine right of kings" stuff going on in Europe - the Tokugawas from the mid-17th century required them to spend alternating years in their capitol, Edo. And by "them" I mean the lords and like half of their massive retinues; their families were often forced to stay in Edo permanently, as basically hostages. Now as you can imagine, the costs of housing and feeding thousands of your dudes (to say nothing of moving them across country, by foot, once a year) were exorbitant, and that was the whole point of the law - to keep the daimyo from amassing enough money to become economic (thus potentially military) rivals. But on the flip side of the coin, all that money was being spent on goods and services, which means that Edo was the place to be if you were a merchant, or a craftsman, or a prostitute, etc., and wanted to get rich or at least make enough to live what we might roughly analogize to a middle-class existence, although it would have been a lot poorer than what we probably think of when we think of the middle class.
On the question of space, I'll just say that the Kanto Plain where Edo was/Tokyo is is vast, with lots of space to spread out. If you look at a map of Tokyo today, you might be amazed to know that many of the locations we (at least foreigners) think of as "central Tokyo," like Shinjuku or Shibuya, were in fact basically countryside as recently as a hundred years ago. Of course that's not to say that there weren't slums, and that they weren't overcrowded and filthy like slums usually are.
I'm going to stop there, but let me recommend some readings. Edward Seidensticker's Low City, High City is a bit dated now but still essential reading for the history of the city. On the question of welfare, check out the "Evolution of Japanese-style Welfare" chapter in Sheldon Garon's Molding Japanese Minds.
Also if you're interested in a 20th century interpretation of what daily life was like in the Edo period, I can't recommend the films of Yamanaka Sadao highly enough. You can find his three best surviving with subtitles here, here, and here.
Follow up - is this figure accurate? We're there not larger cities in the Indian subcontinent or Pakistan or the regions China now occupies?
Edit: were there any larger cities in Asia as a whole? Or the world?
Okay so look like this thread has blown up. But work is work. I was going to wait until the weekends to answer this, but I think I'll divide it into bits and answer one or two parts a day. ^In ^my ^defense ^it's ^a ^large ^question ^^someone ^^do ^^my ^^work ^^for ^^me ^^:(
Feeding Edo
How was such a large population, whatever it was (see other reply) fed? First, rice from all over the almost 8 million koku Shogunate realms (Tokugawa+Hatamoto) throughout Japan was shipped to Edo. Obviously not all of it, likely the majority stayed to feed the local domains. Whether or not the daimyos and their household in Edo also brought their own rice to pay their retainer and staff I actually don't know (probably not, see below). Still, that's a lot of rice flowing into Edo. And that's not counting merchants moving supplies in.
In the Edo, a lot of that rice was paid out to hatamoto samurai. Samurai who did not have a fief was paid in full or part in rice. So count it as a dole if you will. However it's likely the majority of that rice was not actually eaten by the samurai. Instead, it was given to rice merchants who either sold it for money, or used the rice as loan security deposit. The samurai would then go around spending that money and racking up debt and be a stimulus to the economy while being a legal pain-in-the-ass as they scream for debt forgiveness and argue with debtors.
However, even with all that rice coming into Edo, we shouldn't be surprised that the Shogunate was finding it increasingly hard to feed the city, specifically to tackle with soaring rice prices. As part of a very wide-ranging set of new rules called the Kyōhō Reforms by the 8th Shogun Tokugawa Yoshimune in the early to mid 18th century, all domains were encouraged to open up new lands, and land taxes were raised, leading to increased unrest. In addition, the terms of the Sankin Kōtai were slashed so there'd be less people in Edo to eat up all the food. "Gifts" from daimyos (tributes/taxes) were changed from money to rice. This helped to plummet rice prices and restore the Shogunate's finances, but ironically lead to a lot of economic hardship (the higher the price meant the samurai can borrow more which meant they can spent more which allowed merchants to prosper). It also lead to large fluctuations of rice prices until finally these parts of the reform were called off.
Rice alone isn't enough to feed everyone. 1 koku of rice comes to about 1500~1600 cal, and only the mid-upper and upper class would be able to eat 1 koku of rice. Arizono Shōichirō calculated that in Japan on average (not for Edo, but just putting that here, actual numbers varied wildly), in 1861 a person's diet composed of 47% rice. Besides rice, Edo also hosted a very lively fish market (it still does actually). When Edo was smaller, it was the focal supply point of fishes to Musashi province. Now that it was a giant city, it ate a lot of fish. Besides local fishing, Edo imported fish from afar. Everyday, no matter the weather (or so we're told) special cargo ships rush in from as far away as modern Ibaraki prefecture and Izu peninsula, bringing fish into the capital. They try to be as fast as possible, because fish spoil easily. Once they reach the harbour at Nihonbashi the peddlers snatch up all the fish. They then rush as fast as possible to all the restaurants, food stalls, and families that they already received orders from. You see there's no refrigeration, so they couldn't put the fish out on display for sale.
Also sent from those provinces were vegetables, this time to Kanda. Kanda and Nihonbashi were natural places for offloading goods, using rivers and the Edo Castle outer moat for ease of transport by water. Vegetables lasted slightly longer than fish, so there were some stalls that sold vegetables, but most of the transaction were still done by peddlers. We mustn't also count out local farming, of both rice and vegetables, which are clearly visible from surviving maps. While it obviously wasn't enough to supply the entire city, it's especially good to farm vegetables to be sold in the city, as vegetables spoil a lot easier than rice.
A bit after our time period, but here's a list of the most popular dishes in the early 19th century (And no I can't personally actually read it). It lists a lot of different dishes, most of it seem to be easy-to-make, family dishes, probably for home-cooking. There seem to be an emphasis on cheap stuff with lots of volume, and it also lists different ingredients (and so different dishes) for different seasons, which would be the norm in a pre-modern society. Most seem to be making stuff that goes with rice, with the most common ingredients being vegetable and fish, boiled, with miso or soy sause, pickled, or salted (so your traditional Japanese dishes).
Besides eating at home, Edo boasted a lot of restaurants. Ōta Nanbo wrote in the late 18th-early 19th century that Edo had a small restaurant every five steps, and a large one every ten. Even allowing for exaggeration or that he's only describing certain parts, that's very impressive. Most eating places specialized in certain dishes like tempura, sushi, soba, ochazuke, inari sushi, etc, etc. The majority of places seem to have been temporary street-side stalls, if even that. The ochazuke picture for example would have basically been the vender carrying his equipment and supplies and setting up to sell on the street wherever it seems good. In the more permanent restaurants, at least for the lower-class people, the norm seem to have been just sitting down on the tatami, even just by the entrance, and eat. Tables did not become widespread until post-Meiji, and chairs not until post WWII.
More fancy places existed too, with gardens and often multi-stories and everything. Here's the most popular ones in the early 18th century.
Sources
Conrad Totman. Early modern Japan. 1995.
石川英輔. 実見 江戸の暮らし (講談社文庫). 2013.
Charlotte von Verschuer. Trans: Wendy Cobcroft. Rice, Agriculture, and the Food Supply in Premodern Japan 1988. Trans: 2016.
I've heard that they Aztecs had the largest population in Teotihuacan in the 13th or so century, is this true?
u/mustaphamondo already explained a bit about the impact of the Sankin Kotai, we'll leave it at that. I'll chime in and give a bit of info on the "infra" part of your question, esp water distribution.
One thing you have to remember is that Edo was built on an estuary, digging wells was not feasible (brackish water only) and bringing a steady supply of drinkeable and clean water to the exploding population was one of the greatest challenges the Shogunate had to face.
The Shogunate built a large water supply system of aqueducts over the centuries, with a remarkable underground distribution network , bringing fresh water from the river system on the Western side of Edo. The first one, Kanda aqueduct, brought water from the Inokashira pound and was completed as early as 1590, at the very early stages of Edo and before Ieyasu. Another one, Tamagawa Aqueduct was soon added in the mid XVIIth. The Tamagawa Aqueduct was 43 km long, running overland from this point to Yotsuya in Edo, and the denivellation was less than 100m, making it an impressive engineering feast for the time.
For the anecdote, the Haiku poet Basho worked 4 years on the maintenance of the Kanda aqueduct at the end of the XVIIth.
The use of the water from aqueducts was critical, the aqueducts were heavily surveilled, tampering with the aqueduct was, not surprisingly, punishable by death.
The large Meireki fire of 1657 (that destroyed the dungeon of Edo castle) pushed the Shogunate to build 4 more aqueducts, that were stopped being used after 1722 for various reasons (difficult to maintain, etc.), leaving the Tamagawa aqueduct as the main source of fresh water for the whole city.
After its arrival in Yotsuya, water was brought forward through a network of "mini underground aqueducts" looking like this, which in turn distributed water to a network of wells, located in the yards of Nagayas (hosuing complexes) or daimyo domains, see for instance this pic. See also this (underground network on the left, well on the right).
One underground aqueduct had to cross the deep valley of the Kanda river from above, hence the name of the present-day location Suidobashi (the "bridge of the aqueduct") in Tokyo. This crossing is depicted in Hiroshige's print Ochanomizu.
The Tamagawa aqueduct was fully in use until the beginning of the XXth century, and parts are still being used by the Tokyo waterworks system by the way.
It is true that there were 1 million people in Edo, ancient Tokyo. Defeated lords must make their family and the attendants live there as hostage and Shogunate gov must maintain more samurais to control opponents. What sustained the population is rice whose yield is 5 times more than wheat per certain are. Rice was principal food at that era and the population including merchants, craftsmen, farmers, etc is also inferred from the circulation of rice in Edo.