Gateway Connection Timeouts

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
TripAdvisor

Problem

During an on-call investigation, find all error tracking entries where the service name contains 'gateway' and the message contains the phrase 'timed out'.

Timeouts at the gateway.

Tables

err_tracks

Columns: err_id INTEGER, err_type TEXT, message TEXT, svc_name TEXT, severity TEXT, count INTEGER, first_at TEXT

err_tracks: 10 of 200 rows
err_iderr_typemessagesvc_nameseveritycountfirst_at
137TypeErrorCannot read property of undefinedpayment-apierror82026-02-02 01:11:00
174ConnectionTimeoutConnection timed out after 30suser-svcwarning152026-03-03 02:22:00
211OutOfMemoryHeap space exhaustedsearch-apiinfo222026-04-04 03:33:00
248FileNotFoundFile /tmp/data.csv not foundgatewayFatal292026-05-05 04:44:00
285PermissionDeniedAccess denied for user rootworkerERROR362026-06-06 05:55:00
322RateLimitExceededToo many requests from 10.0.0.1auth-svcfatal432026-07-07 06:06:00
359ParseErrorMalformed JSON in request bodypayment-apierror502026-08-08 07:17:00
396nullpointerexceptionStack overflow in recursive calluser-svcwarning572026-09-09 08:28:00
433TYPEERRORDivision by zerosearch-apiinfo642026-01-10 09:39:00
470NullPointerExceptionUnexpected null value at line 42gatewayFatalNULL2026-02-11 10:50:00

Expected output

First 3 of 3 rows
err_iderr_typemessagesvc_nameseveritycountfirst_at
914ConnectionTimeoutConnection timed out after 30sgatewayFatal1552026-05-23 22:02:00
2024ConnectionTimeoutConnection timed out after 30sgatewayFatal3652026-08-25 04:32:00
3134ConnectionTimeoutConnection timed out after 30sgatewayFatal5752026-02-27 10:02:00

Worked solution and explanation

What this is really asking

This is a containment search wearing an incident costume. The word 'contains' is the whole problem: 'timed out' never stands alone in message, it sits inside 'Connection timed out after 30s', so any predicate that compares the whole cell finds nothing. Anyone can write the WHERE; what separates candidates is reading 'contains' as a substring with wildcards on both sides. Write message = 'timed out' or an anchored LIKE 'timed out%' and the query returns zero rows in the middle of an incident, and the on-call concludes the gateway has no timeout problem.


Break down the requirements

Step 1: Match the service as a substring of svc_name

svc_name LIKE '%gateway%' reads the requirement literally: 'gateway' anywhere in the name. On err_tracks the service is stored as exactly 'gateway', so today the pattern and an equality agree. The wildcards are what the prompt asked for, and they keep the query right the day a 'gateway-eu' starts logging.

Step 2: Find the phrase inside message

The only timeout text in the table is 'Connection timed out after 30s'. The phrase starts after 'Connection ', so message = 'timed out' and LIKE 'timed out%' both miss it. Only LIKE '%timed out%' finds it wherever it sits.

Step 3: AND, not OR

Both conditions must hold on the same row. Timeouts also land on 'user-svc' and the other services, and 'gateway' logs plenty of non-timeout errors such as 'File /tmp/data.csv not found'. With OR you would return all of them.


The solution

GATEWAY TIMEOUT ERROR ENTRIES
SELECT
  err_id,
  err_type,
  message,
  svc_name,
  severity,
  count,
  first_at
FROM err_tracks
WHERE svc_name LIKE '%gateway%'
  AND message LIKE '%timed out%'

Common follow-up questions

Common follow-up questions