Find a Target Photo in a Stream
Design a service that ingests photo occurrences and finds exact matches to a target photo within a bounded retention window.
Problem statement
Design a system to find a photo in a stream. For this exercise, assume an authorized user searches a stream they own using one target photo. A match means identical encoded file bytes, not visual similarity, face recognition, or re-encoding equivalence.
Return the matching occurrence identifiers and ingestion times in ingestion order. Keep the most recent 24 hours of accepted arrivals; identical photos arriving as separate events remain separate occurrences, while retrying the same unexpired event ID does not create another occurrence.
Event IDs are issued by the service with a signed 24-hour validity period; expired IDs are rejected, including retries, and deduplication records remain until that validity period ends. The service must never claim a match based solely on a potentially colliding fingerprint.
Searches use bounded pages and an explicit visibility boundary so clients can distinguish no match from unindexed recent data. Cross-stream search, image transformation, and similarity models are outside scope. A paginated search receives a fixed 60-second snapshot lease.
Its eligible occurrences and required blobs remain readable through the lease even if their normal 24-hour retention expires. After the lease ends, return an explicit expiration response; do not silently return a partial continuation.
What to build
- Accept authorized photo events durably and distinguish transport retries from separate repeated photo arrivals.
- Find byte-identical target-photo occurrences in one authorized stream and return ordered, bounded pages with an explicit search visibility boundary.
- Expire occurrences outside the 24-hour window and preserve honest query behavior during indexing delays and retention races.
At scale
- For this exercise, assume 100 photo arrivals per second across all streams, each at most 1 MB, and 20 target searches per second.
- For this exercise, retain 24 hours of arrivals, make healthy ingestion searchable within 5 seconds, and target a 1-second p95 first-page response.
- For this exercise, pages contain at most 100 occurrences; accepted input must survive a worker crash, and overload must be rejected before acknowledgement rather than silently dropped.
- For this exercise, each search snapshot has a non-renewing 60-second lease; normal retention may be extended only for that bounded active-read grace period. Event-ID validity is 24 hours from service issuance.