I too have always been blown away by Shazam and pondered how it could possible index so much content for fast lookups. A few years ago this article was super helpful in helping me understand and learn a lot. Fun read which required a lot of side googling for me
http://coding-geek.com/how-shazam-works/