Design Shazam
Understanding the Problem
🎵 What is Shazam? Shazam listens to a few seconds of music through your phone's microphone, in a noisy bar or a moving car, and tells you which song it is. Under the hood it turns audio into a compact fingerprint, a set of hashes that survive noise and compression, and looks those hashes up in an index built from a large catalog of recordings. A match needs many hashes from the same song lining up at the same time offset.
The same machinery shows up in two other common questions. Copyright detection on uploads (YouTube's Content ID is the well-known example) matches every uploaded video's audio against reference tracks from rights holders. Duplicate content detection finds re-uploads of something already on the platform. Both are "fingerprint the audio, look it up in an index," with different query shapes, so we'll design Shazam first and cover both as deep dives.
Functional Requirements
Core Requirements
- Users should be able to record a short clip (up to ~10 seconds) and get back the matching song, or "no match."
- The catalog team should be able to add new recordings, and they should become recognizable within an hour.
- Uploads to a video or audio platform should be scanned for copyrighted audio from a reference catalog, and for duplicates of existing uploads.
Below the line (out of scope)
- Lyrics, artist pages and streaming links (other services).
- Humming or singing recognition, which needs a different technique (melody matching, not fingerprinting).
- Cover versions and live performances of a song. Fingerprints match a specific recording.
Non-Functional Requirements
Ask your interviewer for scale. Ours: a catalog of 50 million tracks averaging 3.5 minutes, 100 million recognition queries per day, and an upload platform taking 1 million uploads per day.
Core Requirements
- A user should get a result within about 3 seconds of starting to listen, often sooner.
- Recognition must be robust to background noise, phone microphones and lossy compression.
- False positives must be very rare. Naming the wrong song is worse than saying "no match."
- The index must scale to tens of millions of tracks, with new tracks searchable within an hour.
- Upload scans should finish within minutes of upload, before or soon after the content is published.
Below the line (out of scope)
- Resistance to deliberate evasion beyond simple speed and pitch tricks (it's an arms race; we'll touch on it).
- Multi-region active-active indexing.
The arithmetic shapes the index. Suppose the fingerprinter produces about 50 hashes per second of audio. A 3.5-minute track is 210 seconds, so about 10,000 hashes. Across 50M tracks that's roughly 500 billion index entries. If each entry stores a 4-byte track ID and a 4-byte time offset, that's about 4 TB of postings, plus the hash keys. Too big for one machine, comfortable across a few dozen.
Queries are lighter than they look. 100M per day is about 1,200 per second, maybe 5,000 at peak. Each 10-second query has around 500 hashes, so a few million hash lookups per second across the cluster.
The insight to lead with: this is a search problem, not an audio problem. Once audio becomes a bag of hashes with timestamps, recognition is an inverted index lookup followed by a vote. The audio processing just has to produce hashes that are stable under noise.