DEV Community

Cover image for Building soniq: How I Built a Real-Time Speed Music Quiz
DivyanshuLohani
DivyanshuLohani

Posted on AI-assisted

Building soniq: How I Built a Real-Time Speed Music Quiz

How well do you actually know your favorite artist?

Most of us listen to Spotify for hours every week. We swear we can identify a Vishal Dadlani bridge, a Arjit Singh synth intro, or a Kendrick Lamar beat drop in half a second flat. But when you strip away the track title, scramble the choices, start a 10-second countdown, and hit play on a random snippet... things get chaotic very fast.

That was the itch behind soniq.

I wanted to build a fast-paced, high-adrenaline music quiz where you pick any artist in the world get thrown into a rapid-fire round of 10 tracks, and see if your music memory actually holds up.

Here is the story of how I built it, the tech stack behind it, the quirky hurdles of Spotify's audio preview ecosystem, and what it took to take it from a fun weekend prototype to a production-ready web app.

If you want to poke around the code or try it out:

soniq Hero Banner - Fast-paced artist quiz in action


The Core Concept

The premise of soniq is dead simple:

  1. Pick an Artist or Playlist: Search for anyone from Daft Punk to Juice Wrld or tap into your saved Spotify playlists.
  2. 10 Rapid-Fire Clips: You get 10 questions. Each question plays a short audio snippet.
  3. Beat the Clock & Build Streaks: You have 10 seconds per track. The faster you answer, the more points you bank. Answer consecutively to stack streak multipliers.
  4. Global Leaderboard & Challenge Links: Compare scores against other fans worldwide, or generate a 1-click invite link to see if your friends can top your run.

No fluff, no 45-second onboarding videos. Just press play and test your ear.


Tech Stack Overview

I wanted this app to feel lightning fast, responsive on mobile, and resilient to third-party API quirks. Here's what powers it:

  • Frontend: React 18, Vite, TypeScript, Tailwind CSS, Lucide icons
  • Audio Synthesis: Native Web Audio API (for zero-latency UI sound effects and ticks)
  • Backend: Express.js with TypeScript running on Bun / Node
  • Database & ORM: PostgreSQL paired with Prisma
  • Rendering & SEO: Vite SSR + Static Pre-rendering generator + Open Graph tags
  • External APIs: Spotify Web API + Apple Music / iTunes Preview fallback

Designing the Experience: Retro Modern & Mobile-First

If you play a trivia game on your phone and the layout jumps every time an album cover loads, you close the tab. Period.

Mobile UI Screen showing the 100dvh quiz player with countdown ring and answer buttons


The Big Engineering Hurdle: The Spotify Audio Preview Trap

Building a music guessing game sounds straightforward until you meet the Spotify Web API in production.

Here’s the plot twist: Spotify has deprecated or removed 30-second audio preview URLs (preview_url: null) for a massive chunk of their catalog.

If you search an artist like XXXTentacion or Hanuman Kind on Spotify's endpoints today, you will often find that 8 out of 10 tracks return preview_url: null. If you only rely on Spotify's raw preview field, your quiz either crashes or plays dead silence.

The Solution: Dual Audio Resolution Pipeline

To guarantee every quiz has playable, crystal-clear 30-second clips, I built an automated fallback pipeline:

[User Selects Artist]
        │
        ▼
[Fetch Top Tracks from Spotify API]
        │
        ├─► Has valid preview_url? ──► YES ──► Use Spotify 30s MP3
        │
        └─► preview_url is null?
                │
                ▼
        [Query iTunes / Apple Music Search API by ISRC / Track Title]
                │
                ├─► Matched Audio Preview? ──► Cache & Serve Apple Preview
                │
                └─► Still missing? ──► Silently discard & pick alternate track
Enter fullscreen mode Exit fullscreen mode

This ensures that whether a track is from 1975 or last week, the player gets instant, audible playback without buffering stutters.


Real-Time Audio Without Lag: Web Audio API

When someone selects an answer, the feedback has to be instantaneous. Standard <audio> elements can introduce annoying micro-delays on mobile devices when triggering quick click sounds, streaks, or countdown beeps.

Instead of bundling heavy MP3 assets for UI effects, I wrote an in-memory Web Audio synthesizer (audioSynth.ts). It generates synthetic sine and square wave tones directly in the browser's audio buffer:

// Lightweight, zero-latency feedback synthesized via AudioContext
export const playSound = (type: 'correct' | 'wrong' | 'tick' | 'streak') => {
  const ctx = getAudioContext();
  const osc = ctx.createOscillator();
  const gain = ctx.createGain();

  if (type === 'correct') {
    // Upbeat chime sequence
    osc.frequency.setValueAtTime(587.33, ctx.currentTime); // D5
    osc.frequency.exponentialRampToValueAtTime(880.00, ctx.currentTime + 0.15); // A5
  }
  // ...
};
Enter fullscreen mode Exit fullscreen mode

Zero network requests, zero bundle weight, instant feedback.


Connecting Spotify Without Breaking Guest Flow

Another tricky UX challenge was Spotify account connection.

In early builds, connecting Spotify felt clunky. If a user was already logged in as a guest, hitting "Connect Spotify" risked creating duplicate accounts or wiping their local leaderboard rank.

I refactored the auth flow to support progressive account elevation:

  • Anyone can immediately jump in as a Guest and play right away.
  • When you choose to connect Spotify, it securely links your Spotify OAuth tokens to your existing guest session via Prisma instead of resetting your progress.
  • Plus, we pull your actual public and private playlists so you can test yourself on your own curated rotation.

Spotify Connect Modal

Playlist select ui


Static SSR Pre-rendering & SEO Optimization

Single Page Applications (SPAs) are great for dynamic games, but notoriously bad for SEO and social sharing cards. When someone shares their high score link on Twitter or WhatsApp, you want a rich Open Graph preview with an image, title, and preview text—not a blank <div id="root"></div>.

To solve this without having to migrate the entire app to a heavy server framework, I built a static pre-rendering pipeline into the build step:

  1. Client Build: Vite compiles the React app into dist/.
  2. Server Bundle: Bun bundles the server entry into dist-server/entry-server.js.
  3. Pre-render Script: A custom script (scripts/prerender.js) executes the React tree in Node/Bun for all major routes (/, /leaderboard, /about, /terms, etc.) and injects the rendered HTML into static .html files with dedicated Open Graph tags.
  4. Client Hydration: When a user opens the page, React smoothly hydrates over the pre-rendered markup.

What it felt after a break

Building soniq reminded me of a few timeless truths about shipping side projects:

  1. Third-party APIs will always change: Never assume an external field (like preview_url) will exist forever. Always build graceful fallbacks into your data pipeline.
  2. Micro-interactions make or break a game: Haptic feel, zero-latency audio chimes, and smooth countdown bars transform a basic quiz into something genuinely addictive.
  3. Keep the friction near zero: If playing requires 3 sign-up steps, 80% of users leave before their first track. Let people play instantly, and let them sign in when they want to save their high score.

What maybe I can impliment next:

  • Real-Time Multiplayer Duels: 1v1 Player match where you can battle against your friend and using sockets.
  • Custom Community Packs: User-submitted playlists and curated decade challenges (80s Synthwave, 2000s Pop Punk, 90s Hip Hop).

Give soniq.dibbu.dev a spin, see how many tracks you can nail in 10 seconds, and let me know your high score!

Top comments (0)