Disclosure: this post is shared on behalf of TikTok Song Finder, an independent paid tool for identifying music from public TikTok links. The design below is a general implementation pattern, not a claim about measured performance or the exact internals of the service.
A recognition request can produce a match, no match, or a failure to process the input. A credit-based product needs to distinguish these outcomes before charging.
Model outcomes explicitly
type Outcome =
| { kind: "matched"; title: string; artist: string }
| { kind: "no_match" }
| { kind: "unavailable"; retryable: boolean };
An unavailable video is not evidence that the catalog has no matching song. Keep input failure separate from recognition failure so the interface can explain whether a retry might help.
Make retries safe
Give each attempt a server-generated identifier. Record its outcome and credit ledger entry together in a transaction. Add a uniqueness constraint on the ledger reference for that attempt so a duplicate callback cannot deduct twice. Check the balance atomically. A browser timeout must not cause another charge when the user refreshes: return the stored attempt status instead of creating a second attempt. If credits are reserved before processing, model a reservation and its release explicitly so failed requests do not hold credits indefinitely.
Separate matches from listening links
A title and artist may be available even when a particular listening provider has no link. Treat provider links as optional fields. Avoid presenting a search result as a verified recording, especially when a clip contains a remix, sped-up edit, or speech over music.
Test failures as well as success
Cover two requests competing for the last credit, a result delivered twice, a timeout after a result is stored, an inaccessible video, and a match with missing listening links. Assert both the displayed outcome and final ledger balance. A useful invariant is that a single completed match can consume at most one credit.
Explain payment before recognition
Users should see sign-in and payment requirements before starting. TikTok Song Finder uses a one-time $9.99 pack of 10 credits; one credit is used only when a song is found. Credits never expire and there is no subscription. It accepts public TikTok links and is not affiliated with TikTok or ByteDance.
Connecting billing to a durable outcome gives developers a concrete invariant to test and users a clearer explanation of what happened.
Top comments (1)
👍