my history book says stalin was caught completely by surprise by operation barba rossa, but I also heard that this isn't true. So I want to know what historians of reddit think about this
It depends on how the earlier-signed Molotov-Ribbentrop pact is viewed. I would argue that it was Stalin's way of buying time to prepare for invasion - propel industrial production, gather resources for military operation, organise the state to deal with the strain of war, international breathing space, etc. If it is viewed in that light, then, generally speaking, it would stand to reason that Stalin expected invasion and full-scale war at some point. But this does not answer the question of when, or, more specifically, Operation Barbarossa.
However, in terms of invasion, the first thing to bear in mind is the sheer geographical size of Russia. Invasion of such a massive territory in the conquest of lebensraum ("living space") would've been a formidable task in itself, requiring preparation currently unknown to the German army and officials. Up until now, the underlying cause for the German army's success had been exploitation of their opponents' weaknesses, "done so by employing minimal forces against poorly prepared armies that were utterly unsuited to counter or endure Blitzkrieg and whose parent nations often lacked the will to fight and prevail."^(1) Taking into account Germany's hitherto successful invasions, most of their new territories were comprised of European countries; thinking in terms of size, this was indicative of the ability of Blitzkrieg to function at maximum effectiveness in smaller-scale and more condensed geographical areas. This paled in comparison to the necessity of widespread action if the invasion of Russia was to be successful, equally placing a major strain on the German army's ability to keep operations disciplined, tight, and united.
Bearing in mind the aforementioned German military strategy in combination with Russia's scale, it wouldn't surprise me if Stalin hadn't been prepared of the launch of Operation Barbarossa. Arguably, he'd had the time bought by the concessions of the Molotov-Ribbentrop pact to prepare military forces, organise the discipline of statesmen and officials, and concentrate economic production to the war effort - but the German's reliance on shock tactics would mean that the invasion of such a formidable enemy (in terms of physical size and international prestige) certainly wouldn't have been announced loud and proud.
Source:
Edit(s): Correcting some spelling and grammatical errors.
Stalin was warned by intelligence agents, both Soviet and British of the German build up. However, he largely waved away these warnings, which is understandable in part due to the existence of the Molotov-Ribbentrop Pact and the fact that only seven months earlier Germany and the USSR had been negotiating the USSR's entry into the Axis. Additionally, Stalin figured the warnings from Britain were a trick to sour relations between Germany and the USSR, due to Prime Minister Churchill's prior staunch anti-communism. Overall, Stalin thought that Germany and the capitalist powers would fight their war, and then the USSR would be left to deal with the victor. As such significant military preparations were made in the USSR from 39-41, particularly in terms of materiel, but Stalin did not think that any great conflict would be so soon. However, Stalin did take some heed of the warnings and mobilised 800,000 reservists and moved some 30 divisions to the Soviet western border. Of course, this was nowhere near enough compared with Axis' 178 divisions that would invade on June 22.