Your question is partly based on a false premise; the Alliance knew a lot more than you're giving them credit for. In fact, they were quite clear that:
There was a big, threatening something out in the galaxy, heading towards them; Hackett mentions this in the opening cinematic:
Hackett: We just lost contact with two of our deep space outposts. There's something massive on long-range scanners.
Anderson: Is this what Shepard warned us about?
Hackett: I'd stake my life on it.
Anderson: How long do we have?
Hackett: Not long. I've sent word. The fleets are mobilizing.
And Anderson tells you the same in the first in-engine cutscene:
Shepard: What's going on? Why's everyone in such a hurry?
Anderson: Admiral Hackett's mobilizing the fleets. I'm guessing word's made it to Alliance Command... something big's headed our way.
Shepard: The Reapers?
Anderson: We don't know. Not for certain.
And the Defense Committee says it again later in that scene:
Alliance Council: Whole colonies have gone dark. We've lost contact with everything beyond the Sol Relay.
And it's implied by the Alliance Third Fleet war asset description:
When the Reapers came for [Arcturus] station, Singh had already pulled his command ship, the SSV Logan, back to an ideal firing position for its mass accelerator cannons.
This threat was coming from batarian space, which is stated explicitly in the Fall of Earth codex entry (emphasis mine):
The Reapers took Earth in a matter of hours. The Alliance knew the first wave would arrive from batarian space, but they were unprepared for the speed and scale of the attack.
Your follow-up question, how they could be taken by surprise to the extent they were, is much more interesting, and is obliquely answered by the Fall of Earth codex entry I quoted above: the speed and scale of the attack were totally unprecedented. I'm going to dig deeper into both of those, but there's a third contributing factor I want to spend some time on:
They didn't have a lot of intel
Although Shepard (repeatedly) points out that the "something big" is pretty obviously Reapers, Anderson says that they're not certain. There's a good follow-up question in why they weren't certain, which is something not explicitly mentioned1 but for which we can make some educated guesses:
Intelligence from batarian space is scarce. The The Fall of Khar'shan codex entry reveals that what information did get out was vague, and quickly shut down:
Moments after the information minister took to the extranet and announced that unknown ships were destroying all space traffic near Khar'shan, the defense minister declared there was no reason to panic. The planet's comm buoys were destroyed next, creating an ominous silence that has persisted ever since.
And an Alliance News Network article, posted on the BioWare blog a few days before Mass Effect 3 was released, indicates that some information came out of the batarian refugees we later see on the Citadel, but it was inconsistent and evidently hard to turn into actionable intelligence:
According to the batarians, they are neither invaders nor defectors, but refugees. They claim a hostile species has attacked the Hegemony's fleet, bombarding Khar'shan and other batarian planets.
With the Harsa comm buoy system crippled, communication is sporadic at best between far-flung batarians and their government on Khar'shan. Some refugees claim the attackers were Council. Others blame the geth or even the rachni.
This amount of information is enough for the Alliance to figure that something is going on, but isn't nearly enough to tell them that "something" is the Reapers. And, of course, the state of diplomatic relations between the Alliance and the Batarian Hegemony makes it impossible for the Alliance to get first-hand intelligence from that region.
The FTL comm system is hilariously fragile. This got a brief mention in the last bullet, but deserves to be emphasized: the FTL communications system relies on strategically-placed comm buoys, which are basically miniature mass relays, to transmit over long distances; without them, you're still limited by the speed of light. This is all described in the Communications codex entry from the first game, which also notes that comm buoys are typically disrupted during wartime, for obvious reasons:
Comm buoys are maintained in patterns built outward from each mass relay. The buoys are little more than a cluster of primitive, miniature mass relays. Each individual buoy is connected to a partner on another buoy in the network, forming a corridor of low-mass space.
[...]
With this system, the only delay is the light lag between the source or destination and the closest buoy. So long as all parties remain within half a light-second (150,000 km) of buoys, seamless real time communications are possible.
[...]
During wartime, comm buoy networks are the first target of an attack. Once the network is severed, it can take anywhere from weeks to years to get a message out of a contested system.
We know that the Reapers cut certain regions off from the comm buoy network during their invasion (Khar'shan, for example), so it's logical to assume that they'd do something similar in other systems on their way to Earth. The only ways to circumvent this would be to:
- Get a signal out before the Reapers could destroy the buoys
- Send a physical courier ship, which runs into the immediate problem of that ship being easy picking for the Reapers, to say nothing of trying to outrun them (I'll cover Reaper speed shortly)
- Use a QEC, which are still rare by the time of the attack on Earth; in the whole series we only see a handful of people using one
Sensors have technological limitations that prevent more useful intel. This substantially explains why nobody (even the batarians) knew the Reapers were in the galaxy immediately following the events of Arrival, when they were almost certainly making all speed towards the Vular system: sensors in Mass Effect don't work the way they do in, say, Star Wars; there are quasi-realistic limitations on what they're able to sense. These limitations are discussed in the Starships: Sensors codex entry from the very first game (emphasis mine):
"Light lag" prevents sensing in real time at great distances. A ship firing its thrusters at the Charon Relay can be easily detected from Earth, 5.75 light-hours (six billion kilometers) away, but Earth will only see the event five hours and 45 minutes after it occurs. Due to the light-speed limit, defenders can't see enemies coming until they have already arrived.
[...]
[Long-range] sensors include visual, thermographic, and radio detectors that watch and listen for objects in space. A powered ship emits a great deal of energy; the heat of the life support systems; the radiation given off by power plants and electrical equipment; the exhaust of the thrusters. Starships stand out plainly against the near-absolute zero background of space. [Long-range] sensors can be used during FTL travel, but incoming data is significantly distorted by the effect of the mass effect envelope and Doppler shift.
[Short-range] sensors are radars and high resolution ladars (LAser Detection And Ranging) that emit a "ping" of energy and "listen" for return signals. Ladars have a narrower field of view than radar, but ladar resolution allows images of detected objects to be assembled. [Short-range] sensors are useless when a ship is moving at FTL speeds.
Basically the only thing long-range sensors even could tell the Alliance is that there are a lot of energy signatures heading towards them, and all kinds of sensors are stymied by ships travelling at FTL speeds, as the Reapers would have been for most of the trip from Khar'shan to Earth.
The Alliance underestimated the speed of the attack
The most obvious problem is the plain, raw speed of the Reapers. We don't really know exactly how fast they are, but the Reaper Capabilities codex entry from the third game gives an estimated speed of 1.25 lightyears per hour:
The Reapers' thrusters and FTL drives appear to propel them at more than twice the speed of Citadel ships. Estimates of their location in dark space suggest they can travel nearly 30 light-years in a 24-hour period.
At that speed they could travel from Pluto to Earth in about two seconds2, and cross the length of the Asgard3 system in less than one.
Of course, we don't know that the Reapers are moving this fast during their invasion, but they're obviously going pretty dang fast. In the opening cutscene, there's about nine seconds between hearing that the Alliance has lost contact with the moon and receiving the video from London; in those nine seconds, the Reapers have traveled at most 400,000 kilometers and done severe damage to London (we can already see plenty of destruction in the background of that brief video). It's reasonable to assume that they'd have been moving even faster when travelling between systems, since those nine seconds also account for some time travelling at sublight speeds (to make planetfall on Earth).
This speed, ultimately, is a large part of how the Reapers were able to get to the moon so much quicker than Anderson had expected: they have more raw thruster power than anything the Alliance has ever encountered before (and recall that Sovereign was clearly not demonstrating his full capabilities in the first game; in the Battle of the Citadel cutscene, he's moving as quickly as, if not slower than, his geth armada). The other reason is the question of scale, which I'll come back to.
What's more, the Reapers made better time than the Alliance was expecting; the Fall of Earth codex entry reveals that the Reapers skipped straight past the intermediate systems on their way to Earth, entirely bypassing the Alliance's first two lines of defense:
The Reapers bypassed the Sixth and Seventh Fleets at Terra Nova and Eden Prime, flying straight from relay to relay where they could neither be tracked nor intercepted. The tactic was unexpected, since the navies of organic species would never risk coming out of FTL within combat range or leaving enemies at their backs to threaten supply lines.
This also illustrates that the Alliance failed to understand their enemy, which left them more vulnerable than they otherwise might have been; it's not hard to imagine how the Reapers blew past the Alliance's defences, when large portions of the defence was focused on defending against the wrong kind of attack.
The Alliance underestimated the scale of the attack
Radhil has already admirably covered blitz tactics, but I want to mention some specific factors from the series. First, as the Fall of Earth codex entry mentions, the Reapers sent a lot of ships to Earth (emphasis mine):
At Arcturus Station, more than a dozen Reaper capital ships engaged the Alliance's Second, Third, and Fifth Fleets. This was mere screening for the main force. Dozens more capital ships continued through the Charon Relay, where the First Fleet had been lying in wait but was soon destroyed. The Fourth Fleet, near Earth, had a few minutes of advance warning. It stood no better chance.
We have ample evidence that the Reapers completely outclass any organic race, and can pretty trivially tear through anything short of supremely overwhelming force; if caught off-guard, as the Alliance was, it's not hard to imagine several dozen Reaper capital ships absolutely shredding a fleet.
What's more, as that codex entry points out, the Reapers were perfectly willing to divide their forces to get at Earth quicker; if they did so at Arcturus, it seems reasonable to assume that they'd have done it again after getting through the Charon relay, and possibly again at the moon. It's worth noting that they pulled a similar strategy against the turians, who were admiteedly much better-prepared for the attack4, as mentioned in the Battle of Palaven codex entry:
The Reapers countered instantly. Their destroyers performed a jump of their own to the skies above Palaven, beginning orbital strikes on turian cities. The turians, forced to defend the planet, found themselves in a pitched battle far from the relay, from which emerged a seemingly endless line of Reaper ships.
If that's what they did, a force of Reapers could easily have been most of the way to Earth before anyone in the Fourth Fleet could even manage to get a signal off.
All of this being the case, I'm actually more surprised the Alliance had any warning, though (again) we know that they did. We might imagine that various ships managed to get some signals off before being outrun or destroyed by the Reapers, but the information in the game isn't quite detailed enough for us to confirm that.
1 It's even more baffling if you didn't do the Bahak mission. In that version of the story5, Hackett sends some marines to investigate Kenson's disappearance, and they decide to blow up the relay to stall the Reapers. There's an update to the 103rd Marine Division war asset description in this case, which reveals that the Alliance was able to recover some evidence of this mission:
Admiral Hackett dispatched marines to the planet Aratoht to rescue a deep cover agent, Dr. Amanda Kenson. The teams were killed in an explosion that wiped out both the colony and the system's relay. The Alliance spent weeks piecing together scattered radio transmissions, learning that the marines felt they had no choice but to send an asteroid into the relay to prevent invasion by the Reapers. While it bought the Alliance some time, the men and women lost on the mission were a severe blow to the 103rd Marine Corps.
How the Alliance can still doubt the presence of Reapers with this information strains credulity; there are a few mental contortions we can do to make this more sensible, but there's no additional justification given in the game
2 Unfortunately, Wolfram Alpha won't let me account for the maximum distance between the Earth and Pluto, which Space.com gives as about 7.5 billion kilometers; at that distance, it would take about a half-second longer
3 Using the orbital distance of Loki (given in the planet's description in the third game), the outer-most planet of the system, as a boundary; Loki's orbital distance is only 6.8 AU, which makes this a pretty small system. The Utopia system is much larger, and (using Xanadu's orbit as the boundary) would take about 9 seconds to cross.
Using planetary orbits as a boundary isn't consistent with either the game (which shows a farther boundary for each system, often some distance from the outermost planet) or real life (where the boundary is vaguely defined but impossible to calculate in-game); the actual numbers are invariably going to be larger than what I've calculated, but to a first approximation it's as good as we're going to get
4 The reason for the discrepancy is, in part, because the Reapers attacked Palaven somewhat later than they did Earth, and partly because they first assaulted the turian colony world of Taetrus and then launched a propaganda campaign aimed at demoralizing them; this is discussed in the Fall of Taetrus codex entry:
By the time Taetrus went dark, the turians had already learned that the batarians and humans were under attack. [...] The Reapers emerged victorious from the relay and began broadcasting a signal to turian comm buoys--images of Vallum, Taetrus's capital, once again a smoking wreck.
5 Since a lot of the comments on this question talk about what happened "canonically", I think this point is worth emphasizing: very few of the events in the Mass Effect games can be considered objectively "canon"; this was actually a stated goal of series director Casey Hudson, as he said in a 2012 interview:
Hudson: We have a rule in our franchise that there is no canon. You as a player decide what your story is.
BioWare took great pains to ensure that the game still made sense regardless of what choices you make as a player; so if you don't do a particular mission, there will either be a "default" choice (for example, not doing the Bring Down the Sky DLC defaults to an asteroid crashing into Terra Nova) or a sensible alternative (as with Arrival, mentioned in a previous footnote, or with Udina becoming Councillor in the third game).
Basically, if you can make a choice (or if your choice affects an NPC's choice), there is no such thing as an objectively canon choice; there's only the choice that's canon in that particular playthrough