← Questions

Query machines from an API and mark them offline

0
CoreWeaveCodingLast asked Feb 2026

A coding interview question asked in CoreWeave's coding round, last asked Feb 2026. It tests http clients, apis and fleet management.

Write a script against a machine-inventory HTTP API. Fetch every machine, pick out those that should be taken out of service, and call the API to mark each one offline. Requests can fail, and responses can be malformed; the script must keep going and report what it did.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • GET /machines?cursor=<c> returns {"machines": [...], "next_cursor": "<c>" | null}. Each machine is {"id": str, "state": "online" | "offline", "failed_checks": int, "last_heartbeat": int} (epoch seconds).
  • POST /machines/<id>/offline marks one machine offline; it answers 200, or an error status.
  • A machine should go offline when it is online and either failed_checks >= 3 or its last heartbeat is more than 600 seconds old.
  • python mark_offline.py --base-url URL [--dry-run] prints each machine it marked, each failure, and a summary.

Example

now = 10000
m1  online   failed_checks=0  last_heartbeat=9900   -> keep
m2  online   failed_checks=3  last_heartbeat=9950   -> mark offline   # too many failed checks
m3  online   failed_checks=1  last_heartbeat=9300   -> mark offline   # silent for 700 s
m4  offline  failed_checks=5  last_heartbeat=1000   -> skip           # already offline

marked: m2, m3

Constraints

  • Thousands of machines across many pages.
  • The API can time out, return 429 or 5xx, or return a page or a machine record with missing fields.

Clarifying questions

  • What exactly makes a machine eligible, and is that rule configurable?
  • Is marking offline idempotent, and is it safe to retry after a timeout?
  • Is there a limit on how many machines may go offline in one run?
  • Does the API rate-limit, and how is the script authenticated?
  • Should a dry run be the default?

What a strong answer covers

  • Pagination until next_cursor is null; parsing that tolerates and reports bad records instead of crashing.
  • The selection rule as a pure function, tested on its own.
  • Retries with backoff and a cap on timeouts, 429 and 5xx; no retry on 4xx errors that won't change.
  • One failure doesn't stop the run; a summary of marked, skipped and failed machines and a non-zero exit status on failures.
  • A dry-run mode and a safety cap on how many machines one run may take offline.
  • Configuration (base URL, token, thresholds) from flags or environment, and tests against a fake API.

Follow-ups

  • Mark machines concurrently, without exceeding the API's rate limit.
  • The script crashes halfway. How does a rerun avoid repeating or missing work?
  • Run it continuously as a service instead of a one-off script.
  • A bug in the rule would take the whole fleet offline. What guards do you add?

Where it's asked

What it tests

http clients · apis · fleet management

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding