There are several mechanisms Stack Overflow uses to keep spam down:
First, most spam is designed for specific software - Wordpress, phpBB, etc. Since Stack Overflow has a custom codebase from the ground up, that would mean tailoring a spam engine to these specific sites, which I doubt is worth spammers time, since programmers and computer enthusiasts are able to instantly recognize it for what it is.
Second, the software itself has several anti-flood features (see the blog for details) that prevent a user from any one IP from posting too fast. There are also capchas on the sites that try to force the user to prove that they are human if they exhibit robot-like usage patterns.
Third, the software has tools for users of a certain rep to recognize and remove spam. If six users vote a post as spam and/or offensive, it's deleted from the system. Once it hits three votes its banished from the front page, meaning most people visiting won't even see it.
Finally, if spam somehow gets through all these checks, there are moderators that watch the various sites that can instantly remove spam and suspend/delete abusive accounts. Although moderators try to be as vigilant as we can, we also rely on the community to notify us of spam and other forms of abuse through the moderator flag.