DB Olympics

Queries · q130 · VP Platform Engineering · week 1, night 3

Tenant Size vs Carts.remind Job Failure Exposure, 2025

“Were the 10 tenants hit by the November carts.remind job failures large/top-tier accounts, or did exposure look unrelated to merchant size?”

Manager · asked the questionDiego MoralesVP Platform Engineering. Former reliability lead at a payments company. Owns uptime and the integrations merchants depend on.
Analyst · planned the reportLucas MoreauPragmatic: answers the question asked with the simplest reliable report.
Engineer · wrote the SQLOmarPragmatic: the shortest correct query, aggregates first and joins dimensions afterwards, FILTER clauses for conditional counts.

Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told

  1. A business event lands on the VP Platform Engineering's desk

    Week 1; shared with Samuel Whitcombe, Head of Merchant Success

    Leadership wants a review of platform reliability in 2025: failed and slow background jobs, health check failures, rate limiting, webhook delivery problems, and which merchants felt them.

  2. Diego Morales writes to Lucas Moreau

    The manager, at the start of week 1

    Subject: 2025 platform reliability review — what I need by Friday

    Lucas,

    Leadership wants a year-in-review on platform reliability for 2025, and I'm leading it jointly with Samuel Whitcombe (Merchant Success). The deliverable is a memo that tells leadership how reliable the platform actually was last year, where it hurt merchants most, and what that implies for our 2026 investment priorities (reliability engineering headcount, which integrations/carriers to fix or replace, whether we need stricter rate limiting or SLAs). Samuel's side will map our findings to specific merchant relationships and churn risk, so where possible, surface things in a way that can be tied back to individual merchants rather than only platform-wide averages.

    Given you only get a handful of report slots a night, here's what matters most to me, roughly in priority order:

    1. How often did background work actually fail or run late in 2025, and is it getting better or worse? I want a view across the year (not just a single average) so we can see trend, not just a snapshot.
    2. When something broke, which merchants bore the brunt of it? I'd rather see a short list of the merchants hit hardest by job failures, slow jobs, or delivery problems than a platform-wide blended number — that's what Samuel needs to go have conversations.
    3. Were there periods where our own health checks told us something was wrong, and did that line up with the times merchants complained or things failed? I want to know if our monitoring is actually catching problems early or if we're flying blind.
    4. Are merchants getting throttled by our rate limits in ways that look like it's hurting their business, rather than protecting us? I want to know if this is a tuning problem or a capacity problem.
    5. How reliable are our webhook deliveries to merchants' own systems, and are there particular integrations or providers that are chronically troublesome? This feeds a build-vs-fix-vs-drop decision on a couple of integration partners.

    If you have to cut scope to fit your nightly slots, protect #1 and #2 — those are what the memo absolutely must answer. The rest can wait or be addressed at a higher level if time runs short.

    Let me know if anything above is ambiguous before you spend a slot on it.

    Diego

    A note from the Head of Merchant Success, Samuel Whitcombe

    Subject: Platform reliability review — what I need from my side

    Hi Lucas,

    As you pull together the 2025 reliability picture, here's what matters from the merchant-health side:

    1. Did our largest merchants actually feel this? For our top-tier accounts (the ones I sit QBRs with this month), can we tell whether job failures, health check issues, rate limiting or webhook problems clustered on their tenants more than the long tail — and whether it tracked with order volume or came out of nowhere?
    2. Did reliability issues coincide with commercial pain? I'd like to know if the merchants hit hardest by these issues also show signs of strain elsewhere — support tickets spiking, churn or downgrades, slower sales — so I can tell if this is a cause or just a correlation worth flagging.
    3. Any repeat offenders going into 2026? Were there a handful of merchants who got hit repeatedly through the year rather than a one-off bad week platform-wide? I want to walk into January reviews knowing who to proactively address before they raise it.

    Happy to flag specific merchant names if that helps scope the analysis.

    Best, Samuel

  3. Lucas Moreau plans the night

    The analyst · week 1, night 3, request 1 of 3

    Night 2 reframed the whole job-reliability story: queue delay and run duration are flat and tiny every single week (no "lateness" problem exists at all), and ALL 20 failures in the entire Oct-Dec window happened in one week (2025-11-24) in one handler (carts.remind), hitting exactly 10 tenants. So this isn't a chronic reliability problem - it's one contained one-week incident tied to the abandoned-cart-reminder job. Report 3 showed something genuinely useful: the health-check unhealthy rate spiked (2.44% vs a ~1% baseline) in that exact same week, suggesting monitoring did catch it. Given this, tonight I pivot to what Samuel needs about those 10 tenants specifically (are they top-tier/large accounts, did it track with order volume, did it coincide with ticket pain) since that's now answerable precisely rather than generically, and I use my third slot to open up webhook delivery reliability (Diego's #5), which I haven't touched yet and which is a more directly merchant-facing failure mode than internal jobs turned out to be.

    Tenant Size vs Carts.remind Job Failure Exposure, 2025
    Question
    Were the 10 tenants hit by the November carts.remind job failures large/top-tier accounts, or did exposure look unrelated to merchant size?
    One row per
    tenant
    Columns
    • tenant_name
    • total_orders_2025
    • total_revenue_eur_2025
    • revenue_rank
    • was_affected_by_nov_carts_remind_failure
  4. Omar writes the SQL

    The engineer · 1 dry run on the empty schema, then the submission

    Dry run 1 · STATUS: COMPILES (dry run on the empty schema, no data read)
    WITH order_rev AS (
      SELECT
        o.tenant_id,
        COUNT(*) AS total_orders_2025,
        SUM(o.grand_total / er.rate) AS total_revenue_eur_2025
      FROM orders o
      JOIN exchange_rates er
        ON er.base_code = 'EUR'
       AND er.quote_code = o.currency_code
       AND er.as_of = DATE(o.placed_at)
      WHERE o.placed_at >= TIMESTAMP '2025-01-01'
        AND o.placed_at < TIMESTAMP '2026-01-01'
      GROUP BY o.tenant_id
    ),
    affected AS (
      SELECT DISTINCT jr.tenant_id
      FROM job_runs jr
      JOIN jobs j ON j.id = jr.job_id
      WHERE j.handler = 'carts.remind'
        AND jr.status = 'failed'
        AND jr.queued_at >= TIMESTAMP '2025-11-01'
        AND jr.queued_at < TIMESTAMP '2025-12-01'
    ),
    ranked AS (
      SELECT
        t.id AS tenant_id,
        t.name AS tenant_name,
        COALESCE(orv.total_orders_2025, 0) AS total_orders_2025,
        COALESCE(orv.total_revenue_eur_2025, 0) AS total_revenue_eur_2025,
        DENSE_RANK() OVER (ORDER BY COALESCE(orv.total_revenue_eur_2025, 0) DESC) AS revenue_rank,
        CASE WHEN a.tenant_id IS NOT NULL THEN 'Yes' ELSE 'No' END AS was_affected_by_nov_carts_remind_failure
      FROM tenants t
      LEFT JOIN order_rev orv ON orv.tenant_id = t.id
      LEFT JOIN affected a ON a.tenant_id = t.id
    )
    SELECT
      tenant_name,
      total_orders_2025,
      ROUND(total_revenue_eur_2025, 2) AS total_revenue_eur_2025,
      revenue_rank,
      was_affected_by_nov_carts_remind_failure
    FROM ranked
    ORDER BY was_affected_by_nov_carts_remind_failure DESC, revenue_rank ASC, tenant_name ASC
    LIMIT 30

    “Query compiles cleanly with the expected columns. Submitting.”

    Submitted · the SQL of the last dry run, unchanged · Submitted to tonight's batch. Your work on this request is done.

    “Submitted. The report ranks all tenants by 2025 EUR-converted order revenue, flags the ones hit by November carts.remind job failures, and returns the 10 affected tenants plus the next ~20 largest unaffected ones (sorted Yes-first, then by revenue rank) so Lucas can see at a glance whether the outage concentrated on top-tier accounts or spread across the tail.”

  5. The report comes back overnight

    As Lucas Moreau saw it, from the small dataset the agents worked on

    tenant_name            | total_orders_2025 | total_revenue_eur_2025 | revenue_rank | was_affected_by_nov_carts_remind_failure
    -----------------------+-------------------+------------------------+--------------+-----------------------------------------
    Cragsley Outfitters    |              3635 |              724835.93 |            1 | Yes                                     
    Marrowby & Vane        |              1758 |              288909.93 |            4 | Yes                                     
    Cinder Peak Sports Co. |               338 |              124756.84 |            6 | Yes                                     
    Fennel & Flint         |               389 |               65764.13 |            7 | Yes                                     
    Petalcourt Beauty      |               706 |               63508.22 |            8 | Yes                                     
    Kibblewick             |               672 |               23801.41 |           14 | Yes                                     
    Ampfeld Elektronik     |                 0 |                    0.0 |           58 | Yes                                     
    Brennquell Kaffee      |                 0 |                    0.0 |           58 | Yes                                     
    Gratlinie Outdoor      |                 0 |                    0.0 |           58 | Yes                                     
    Studio Vrij            |                 0 |                    0.0 |           58 | Yes                                     
    OfficeHub Nordic       |               170 |              428472.93 |            2 | No                                      
    Castell Fasteners      |               159 |              387619.54 |            3 | No                                      
    Deskline Supplies      |                75 |              285178.35 |            5 | No                                      
    Kayak Corner           |               109 |               40600.69 |            9 | No                                      
    Fell & Fjell           |                85 |               36717.18 |           10 | No                                      
    Grind Collective       |              1111 |               25610.52 |           11 | No                                      
    Oakhurst Tailoring     |               165 |               25311.11 |           12 | No                                      
    Velvet Ash             |               134 |               24443.06 |           13 | No                                      
    Circuit Harbor         |                19 |               22953.82 |           15 | No                                      
    Coastline Interiors    |               155 |               21468.31 |           16 | No                                      
    Willow & Wren          |                97 |                19084.7 |           17 | No                                      
    Nordic Bloom Cosmetics |               151 |                19074.7 |           18 | No                                      
    Juniper Apothecary     |               157 |               18018.14 |           19 | No                                      
    Honeycomb Larder       |               620 |               17674.84 |           20 | No                                      
    Bytefield              |                23 |               13014.33 |           21 | No                                      
    The Balm Room          |               104 |               12921.67 |           22 | No                                      
    Thistlecombe           |                92 |               12570.49 |           23 | No                                      
    Meadow Row             |                24 |                9825.26 |           24 | No                                      
    Fjordline Wear         |                57 |                8615.11 |           25 | No                                      
    Courtside Collective   |                20 |                8514.48 |           26 | No                                      
    (30 rows)
  6. What came of it

    The memo and the queries that followed; links found by title, so inferred

    Lucas Moreau's memo to Diego Morales at the end of the week:

    • 3. It did reach top-tier accounts, not just the long tail. Of the 10 affected tenants, 6 had meaningful 2025 volume, including Cragsley Outfitters — our #1 tenant by 2025 EUR revenue — plus tenants ranked #4, #6, #7, #8. The other 4 affected tenants had zero 2025 orders (likely inactive/test accounts). Source: "Tenant Size vs Carts.remind Job Failure Exposure." I'm confident this wasn't volume-driven — small and large affected tenants had identical failure counts (2 each); it looks tied to a feature flag/config, not load.

    Later queries that build on this report:

    It builds on:

  7. It becomes benchmark query q130

    Changed only where the benchmark needs the same result on every system

    • spellingfetch first
    • spellingdate cast
    • determinismtie-breaker: tenant names are not unique; ranked has one row per tenant_id
    • numericsdocs/NUMERICS.md: rounding removed; results keep full precision
    • numericsdocs/NUMERICS.md: x / exchange rate cast to NUMERIC(18,6)
    • made explicita selected t.col gets AS col, its standard name made explicit (2×)
    • determinismthe standard leaves the place of NULLs in a sort to the implementation: NULLS LAST ascending, NULLS FIRST descending, as in the reference results (5×)
    • placeholderfetch first
    The benchmark text, against the submitted SQL
    WITH order_rev AS (  SELECT    o.tenant_id,    o.tenant_id AS tenant_id,    COUNT(*) AS total_orders_2025,    SUM(o.grand_total / er.rate) AS total_revenue_eur_2025    SUM(CAST(o.grand_total / er.rate AS NUMERIC(18,6))) AS total_revenue_eur_2025  FROM orders o  JOIN exchange_rates er    ON er.base_code = 'EUR'   AND er.quote_code = o.currency_code   AND er.as_of = DATE(o.placed_at)   AND er.as_of = CAST(o.placed_at AS DATE)  WHERE o.placed_at >= TIMESTAMP '2025-01-01'    AND o.placed_at < TIMESTAMP '2026-01-01'  GROUP BY o.tenant_id),affected AS (  SELECT DISTINCT jr.tenant_id  SELECT DISTINCT jr.tenant_id AS tenant_id  FROM job_runs jr  JOIN jobs j ON j.id = jr.job_id  WHERE j.handler = 'carts.remind'    AND jr.status = 'failed'    AND jr.queued_at >= TIMESTAMP '2025-11-01'    AND jr.queued_at < TIMESTAMP '2025-12-01'),ranked AS (  SELECT    t.id AS tenant_id,    t.name AS tenant_name,    COALESCE(orv.total_orders_2025, 0) AS total_orders_2025,    COALESCE(orv.total_revenue_eur_2025, 0) AS total_revenue_eur_2025,    DENSE_RANK() OVER (ORDER BY COALESCE(orv.total_revenue_eur_2025, 0) DESC) AS revenue_rank,    DENSE_RANK() OVER (ORDER BY COALESCE(orv.total_revenue_eur_2025, 0) DESC NULLS FIRST) AS revenue_rank,    CASE WHEN a.tenant_id IS NOT NULL THEN 'Yes' ELSE 'No' END AS was_affected_by_nov_carts_remind_failure  FROM tenants t  LEFT JOIN order_rev orv ON orv.tenant_id = t.id  LEFT JOIN affected a ON a.tenant_id = t.id)SELECT  tenant_name,  total_orders_2025,  ROUND(total_revenue_eur_2025, 2) AS total_revenue_eur_2025,  total_revenue_eur_2025 AS total_revenue_eur_2025,  revenue_rank,  was_affected_by_nov_carts_remind_failureFROM rankedORDER BY was_affected_by_nov_carts_remind_failure DESC, revenue_rank ASC, tenant_name ASCLIMIT 30ORDER BY was_affected_by_nov_carts_remind_failure DESC NULLS FIRST, revenue_rank ASC NULLS LAST, tenant_name ASC NULLS LAST, tenant_id NULLS LAST{{fetch_first(30)}}
    WITH order_rev AS (
      SELECT
        o.tenant_id AS tenant_id,
        COUNT(*) AS total_orders_2025,
        SUM(CAST(o.grand_total / er.rate AS NUMERIC(18,6))) AS total_revenue_eur_2025
      FROM orders o
      JOIN exchange_rates er
        ON er.base_code = 'EUR'
       AND er.quote_code = o.currency_code
       AND er.as_of = CAST(o.placed_at AS DATE)
      WHERE o.placed_at >= TIMESTAMP '2025-01-01'
        AND o.placed_at < TIMESTAMP '2026-01-01'
      GROUP BY o.tenant_id
    ),
    affected AS (
      SELECT DISTINCT jr.tenant_id AS tenant_id
      FROM job_runs jr
      JOIN jobs j ON j.id = jr.job_id
      WHERE j.handler = 'carts.remind'
        AND jr.status = 'failed'
        AND jr.queued_at >= TIMESTAMP '2025-11-01'
        AND jr.queued_at < TIMESTAMP '2025-12-01'
    ),
    ranked AS (
      SELECT
        t.id AS tenant_id,
        t.name AS tenant_name,
        COALESCE(orv.total_orders_2025, 0) AS total_orders_2025,
        COALESCE(orv.total_revenue_eur_2025, 0) AS total_revenue_eur_2025,
        DENSE_RANK() OVER (ORDER BY COALESCE(orv.total_revenue_eur_2025, 0) DESC NULLS FIRST) AS revenue_rank,
        CASE WHEN a.tenant_id IS NOT NULL THEN 'Yes' ELSE 'No' END AS was_affected_by_nov_carts_remind_failure
      FROM tenants t
      LEFT JOIN order_rev orv ON orv.tenant_id = t.id
      LEFT JOIN affected a ON a.tenant_id = t.id
    )
    SELECT
      tenant_name,
      total_orders_2025,
      total_revenue_eur_2025 AS total_revenue_eur_2025,
      revenue_rank,
      was_affected_by_nov_carts_remind_failure
    FROM ranked
    ORDER BY was_affected_by_nov_carts_remind_failure DESC NULLS FIRST, revenue_rank ASC NULLS LAST, tenant_name ASC NULLS LAST, tenant_id NULLS LAST
    FETCH FIRST 30 ROWS ONLY
    10 ms100 ms1 sHyper55.8 msDuckDB19.3 msGizmoSQL28.3 msclickhouse_brew220 msFirebolterrorDataFusion104 msClickHouseerror
    • Firebolt{ "errors": [ { "description": "Line 5, Column 28: Operations between decimals with different precision and scale is not supported at the moment. Explicitly cast one of the decimals to other decimal precision and scale." } ], "query": { "query_id": "49726046-338f-4949-bf3c-6acd3894ffd7", "query_labe
    • ClickHouseCode: 69. DB::Exception: Decimal result's scale is less than argument's one: while executing function divide on arguments __table4.grand_total Decimal(14, 4) Decimal64(size = 0), __table5.rate Decimal(12, 6) Decimal64(size = 0). (ARGUMENT_OUT_OF_BOUND)
  8. Everything, as recorded

    The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted

    Omar's whole session, 7 turns
    • The request, as Omar received it
      Report request from Lucas Moreau (analyst for the VP Platform Engineering):
      
      Title: Tenant Size vs Carts.remind Job Failure Exposure, 2025
      Question: Were the 10 tenants hit by the November carts.remind job failures large/top-tier accounts, or did exposure look unrelated to merchant size?
      Grain: one row per tenant
      Columns:
      - tenant_name
      - total_orders_2025
      - total_revenue_eur_2025
      - revenue_rank
      - was_affected_by_nov_carts_remind_failure
      Details: Tables: orders (placed_at in 2025, any status) for total_orders_2025 and total_revenue_eur_2025 (sum of grand_total converted to EUR using exchange_rates: base_code='EUR', quote_code=orders.currency_code, as_of matching date(placed_at), amount_eur = grand_total / rate). revenue_rank = dense rank of tenants by total_revenue_eur_2025 descending (1 = largest). was_affected_by_nov_carts_remind_failure = 'Yes' if the tenant has at least one row in job_runs joined to jobs (job_runs.job_id = jobs.id) where jobs.handler = 'carts.remind', job_runs.status = 'failed', and job_runs.queued_at in November 2025, else 'No'. Order by was_affected_by_nov_carts_remind_failure descending (Yes first), then revenue_rank ascending. Limit to 30 rows so all 10 affected tenants appear plus the next ~20 largest unaffected tenants for comparison.
      
      Check your query with the warehouse's dry_run tool, then hand it in with submit.
    • Omar calls dry_run
      WITH order_rev AS (
        SELECT
          o.tenant_id,
          COUNT(*) AS total_orders_2025,
          SUM(o.grand_total / er.rate) AS total_revenue_eur_2025
        FROM orders o
        JOIN exchange_rates er
          ON er.base_code = 'EUR'
         AND er.quote_code = o.currency_code
         AND er.as_of = DATE(o.placed_at)
        WHERE o.placed_at >= TIMESTAMP '2025-01-01'
          AND o.placed_at < TIMESTAMP '2026-01-01'
        GROUP BY o.tenant_id
      ),
      affected AS (
        SELECT DISTINCT jr.tenant_id
        FROM job_runs jr
        JOIN jobs j ON j.id = jr.job_id
        WHERE j.handler = 'carts.remind'
          AND jr.status = 'failed'
          AND jr.queued_at >= TIMESTAMP '2025-11-01'
          AND jr.queued_at < TIMESTAMP '2025-12-01'
      ),
      ranked AS (
        SELECT
          t.id AS tenant_id,
          t.name AS tenant_name,
          COALESCE(orv.total_orders_2025, 0) AS total_orders_2025,
          COALESCE(orv.total_revenue_eur_2025, 0) AS total_revenue_eur_2025,
          DENSE_RANK() OVER (ORDER BY COALESCE(orv.total_revenue_eur_2025, 0) DESC) AS revenue_rank,
          CASE WHEN a.tenant_id IS NOT NULL THEN 'Yes' ELSE 'No' END AS was_affected_by_nov_carts_remind_failure
        FROM tenants t
        LEFT JOIN order_rev orv ON orv.tenant_id = t.id
        LEFT JOIN affected a ON a.tenant_id = t.id
      )
      SELECT
        tenant_name,
        total_orders_2025,
        ROUND(total_revenue_eur_2025, 2) AS total_revenue_eur_2025,
        revenue_rank,
        was_affected_by_nov_carts_remind_failure
      FROM ranked
      ORDER BY was_affected_by_nov_carts_remind_failure DESC, revenue_rank ASC, tenant_name ASC
      LIMIT 30
    • The warehouse answers
      STATUS: COMPILES (dry run on the empty schema, no data read)
      COLUMNS: tenant_name, total_orders_2025, total_revenue_eur_2025, revenue_rank, was_affected_by_nov_carts_remind_failure
    • OmarQuery compiles cleanly with the expected columns. Submitting.
    • Omar calls submit
      WITH order_rev AS (
        SELECT
          o.tenant_id,
          COUNT(*) AS total_orders_2025,
          SUM(o.grand_total / er.rate) AS total_revenue_eur_2025
        FROM orders o
        JOIN exchange_rates er
          ON er.base_code = 'EUR'
         AND er.quote_code = o.currency_code
         AND er.as_of = DATE(o.placed_at)
        WHERE o.placed_at >= TIMESTAMP '2025-01-01'
          AND o.placed_at < TIMESTAMP '2026-01-01'
        GROUP BY o.tenant_id
      ),
      affected AS (
        SELECT DISTINCT jr.tenant_id
        FROM job_runs jr
        JOIN jobs j ON j.id = jr.job_id
        WHERE j.handler = 'carts.remind'
          AND jr.status = 'failed'
          AND jr.queued_at >= TIMESTAMP '2025-11-01'
          AND jr.queued_at < TIMESTAMP '2025-12-01'
      ),
      ranked AS (
        SELECT
          t.id AS tenant_id,
          t.name AS tenant_name,
          COALESCE(orv.total_orders_2025, 0) AS total_orders_2025,
          COALESCE(orv.total_revenue_eur_2025, 0) AS total_revenue_eur_2025,
          DENSE_RANK() OVER (ORDER BY COALESCE(orv.total_revenue_eur_2025, 0) DESC) AS revenue_rank,
          CASE WHEN a.tenant_id IS NOT NULL THEN 'Yes' ELSE 'No' END AS was_affected_by_nov_carts_remind_failure
        FROM tenants t
        LEFT JOIN order_rev orv ON orv.tenant_id = t.id
        LEFT JOIN affected a ON a.tenant_id = t.id
      )
      SELECT
        tenant_name,
        total_orders_2025,
        ROUND(total_revenue_eur_2025, 2) AS total_revenue_eur_2025,
        revenue_rank,
        was_affected_by_nov_carts_remind_failure
      FROM ranked
      ORDER BY was_affected_by_nov_carts_remind_failure DESC, revenue_rank ASC, tenant_name ASC
      LIMIT 30
    • The warehouse answers
      Submitted to tonight's batch. Your work on this request is done.
    • OmarSubmitted. The report ranks all tenants by 2025 EUR-converted order revenue, flags the ones hit by November `carts.remind` job failures, and returns the 10 affected tenants plus the next ~20 largest unaffected ones (sorted Yes-first, then by revenue rank) so Lucas can see at a glance whether the outage concentrated on top-tier accounts or spread across the tail.