Successful Production Deploys

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
Airbnb

Problem

Slow production rollouts are under investigation, and the release team wants every production deployment in deploy_logs that recorded a duration, listed from the longest-running to the shortest. When two ran for exactly the same length, the more recent deploy goes first.

Successful production deploys with duration.

Tables

deploy_logs

Columns: log_id INTEGER, svc_name TEXT, version TEXT, env_name TEXT, status TEXT, deploy_at TEXT, dur_secs INTEGER, author TEXT

deploy_logs: 10 of 200 rows
log_idsvc_nameversionenv_namestatusdeploy_atdur_secsauthor
131payment-apiv1.0.2stagingfailed2026-02-02 01:11:0023bob
162user-svcv1.1.0devrolled_back2026-03-03 02:22:0036charlie
193search-api2.0.0canaryin_progress2026-04-04 03:33:0049dana
224gatewayv2.1.0ProductionSuccess2026-05-05 04:44:0062eve
255notif-svc2.1.1STAGINGFAILED2026-06-06 05:55:0075frank
286analyticsv3.0.0-rc1productionsuccess2026-07-07 06:06:0088Alice
317ml-servingv1.0.3stagingfailed2026-08-08 07:17:00NULLBOB
348auth-svcv1.0.1devRolled_Back2026-09-09 08:28:00114alice
379Payment-APIv1.0.2canaryin_progress2026-01-10 09:39:00127bob
410user-svcv1.1.0ProductionSuccess2026-02-11 10:50:00140charlie

Expected output

First 5 of 58 rows
log_idsvc_nameversionenv_namestatusdeploy_atdur_secsauthor
1526analyticsv3.0.0-rc1ProductionSuccess2026-02-19 22:26:00608Alice
10003246analyticsv3.0.0-rc1ProductionSuccess2022-10-19 22:26:00608Alice
10003290user-svcv1.1.0productionsuccess2026-09-07 18:30:00580charlie
2828auth-svcv1.0.1ProductionSuccess2026-08-05 16:08:00554alice
1216gatewayv2.1.0productionsuccess2026-01-09 12:36:00478eve

Worked solution and explanation

What this really asks

Strip the release-team framing and this is a filter on a dirty label wrapped around a null-guarded sort. Anyone can write the WHERE. The three things that separate candidates are all in the data. First, env_name spells production as both 'production' and 'Production', so env_name = 'production' keeps 28 of the 58 deploys that qualify. Second, eight production deploys never recorded a dur_secs, and leaving them in puts untimed rows in a list about how long rollouts took. Third, every production duration shows up exactly twice, so sorting on dur_secs alone leaves each pair in whatever order the engine hands back, while the team asked for the more recent deploy first.

Step 1: Fold the casing before comparing

Compare LOWER(env_name) to 'production' so every spelling of the environment counts once. The sample rows show 'Production' and 'production' side by side. That is the moment to normalize, not after the result comes back short.

Step 2: Drop the untimed deploys

Add dur_secs IS NOT NULL to the same WHERE. A rollout with no timing cannot be placed by length, and the guard has to remove those rows before the sort. You cannot hope the sort will push them out of the way.

Step 3: Sort longest first, newest wins a tie

ORDER BY dur_secs DESC, deploy_at DESC. Duration drives the order and deploy_at decides each tied pair. Because deploy_at is a sortable timestamp string, its descending order is chronological.

Fold the casing, keep timed production rows, sort longest first
SELECT log_id, svc_name, version, env_name, status, deploy_at, dur_secs, author
FROM deploy_logs
WHERE LOWER(env_name) = 'production'
  AND dur_secs IS NOT NULL
ORDER BY dur_secs DESC, deploy_at DESC

Common follow-up questions