HardBusiness Analytics High Frequency
Parsing Audit Telemetry with JSONB Operators
Frequently Asked By:MicrosoftGoogleStripe
Interactive In-Browser Workspace
Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.
Problem Statement
Query the `telemetry_logs` table to extract fields from the `payload` JSONB column.
Extract:
1. `log_id`
2. `feature_name`: Extracted as text using `payload->>'feature'`
3. `duration_ms`: Extracted as integer using `(payload->>'duration_ms')::int`
4. `status`: Extracted as text using `payload->>'status'`
Filter to only include records where:
- `payload->>'feature'` equals `'vector_search_v2'`
- `payload->>'status'` equals `'success'`
Order results by `duration_ms` descending to see slowest runs first.
Why Technical Interviewers Ask This
CloudScale's engineering team emits high-throughput audit telemetry logs into a PostgreSQL table with a `jsonb` payload. Product analytics wants to inspect high-latency executions for a new beta feature flag.
Common Pitfalls & Interview Traps
Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass business analytics constructs.
Canonical Modern SQL Solution
PostgreSQL 16 / ANSI SQLSELECT
log_id,
payload->>'feature' AS feature_name,
(payload->>'duration_ms')::int AS duration_ms,
payload->>'status' AS status
FROM telemetry_logs
WHERE payload->>'feature' = 'vector_search_v2'
AND payload->>'status' = 'success'
ORDER BY duration_ms DESC;Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Business Analytics. It meets the target criteria: Extracted telemetry metrics with log_id, feature_name, duration_ms, and status for vector_search_v2 successes.Edge Cases to Verbally Clarify with Your Interviewer
The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.
Frequently Asked Follow-Up Questions
What makes this question a favorite among Microsoft and Google interviewers?
Interviewers use this problem to test whether candidates write defensive, scalable Business Analytics queries that run efficiently on multi-million row production databases without excessive memory usage.
How does the query optimizer execute this query?
Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.