HTTP Calls, Retries & REST APIs
- Write an HTTP client that retries only the failures worth retrying
- Back off exponentially and honor a Retry-After header
- Build a small REST service with the right status code for each case
- Test a service through its request handler, without a network
At SWE I and SWE II, a GitHub interview day has usually meant two technical rounds and a culture round. In 2025 and 2026 one of those is often Battleship, and the other is often about HTTP. A SWE II candidate in March 2026 listed it as "Set up some HTTP calls." A SWE I candidate in February 2025 was told ahead of time to expect "a battleship question and an API question."
The API round comes in two flavors. In the first you write a client: call an API, parse what comes back, send data to a server and cope when that server misbehaves. In the second you build the service yourself, a small REST API over HTTP, and talk through how it would hold up. Below is one problem of each kind, worked in Python.
What the GitHub API coding round looks like
The client version has the longest history, asked from 2021 through March 2026. In September 2024 one final round asked for code that fetches data from an API and puts it into a map, and another candidate spent two sessions fetching and parsing API data.
A February 2022 onsite shows the full shape. You cloned a repo holding a small server written in Go, then wrote a program that read an array of objects from a JSON file and sent them to one of its endpoints with POST requests. The server failed on purpose, so the job was to catch the errors and retry. A 2021 version was similar: process files, call a REST API and debug issues in your own editor and language.
The build-it version is newer. A senior candidate in September 2026 was told one live coding session would be "building a rest api http service." A SWE II candidate in December 2024 was told the two technicals were a Big O round and a REST API design round, and a London candidate in September 2024 had an API design round too. For a Staff loop in 2022, two pair-programming sessions were described as API design work: debugging, new requirements, then fault tolerance and scale. When the round is design only, with no code, the API design lesson covers it.
Not every loop has an HTTP round. A November 2026 senior loop paired Battleship with a JSON query engine instead, which the next lesson works through.
Both versions test the same knowledge from opposite ends of the wire. The client has to read status codes and decide what to do. The service has to send the right ones. If you know which codes mean "try again" and which mean "stop," you can do either round.
Retries, backoff and status codes
Sort every outcome into three buckets before you write a loop. A 2xx is done. A failure that might pass on a second try gets retried: a dropped connection, a timeout, 429 Too Many Requests, and the 5xx family, mainly 500, 502, 503 and 504. Everything else in the 4xx range is your fault, and sending the same request again will get the same answer.
- 400 or 422 means the body is wrong. Log the record and move on.
- 401 or 403 means the credentials are wrong. Stop the whole run, since every request will fail.
- 404 means the path or the id is wrong. Retrying will not create it.
- 409 Conflict on a create often means the record already exists. For an upload that is usually success.
- 429 means slow down. If the response carries a Retry-After header, wait that long. It is usually a number of seconds, though the spec also allows a date.
Between retries, wait longer each time. Exponential backoff doubles the wait: one second, then two, then four. That gives a struggling server room to recover, where a tight retry loop hammers it while it's already down. Cap the number of attempts so one bad record can't hang the run, and cap the wait too.
import timeimport requestsRETRYABLE = {429, 500, 502, 503, 504}def post_with_retries(url, payload, max_attempts=4, base_delay=1.0): for attempt in range(1, max_attempts + 1): try: response = requests.post(url, json=payload, timeout=5) except requests.RequestException: response = None # connection error or timeout: retryable if response is not None and response.status_code not in RETRYABLE: return response # success, or a 4xx that retrying won't fix if attempt == max_attempts: break retry_after = response.headers.get("Retry-After") if response is not None else None delay = float(retry_after) if retry_after else base_delay * 2 ** (attempt - 1) time.sleep(delay) raise RuntimeError("gave up after " + str(max_attempts) + " attempts")Two details in that helper matter more than they look. The timeout on the request keeps one hung connection from stalling everything. And the exception branch catches only request errors, so a typo in your own code still crashes loudly. A bare except: hides your bugs behind retries.
Upload records to a flaky server
This is the client round, something like the February 2022 version plus the fetch-and-parse step from 2024 to 2026 loops. First you load the records you fetched into a map keyed by id. Then you upload each one to a server that fails some requests on purpose, retrying the ones worth retrying.
A live round would hand you a real server to call. Here the server is a script of answers, so the tests can run without a network and every wait is counted instead of slept. Write _post as the one place that talks to the server, the way you'd wrap a real HTTP call.
Upload Records With Retries and Backoff
Problem
Uploader that sends records to a flaky server. The constructor takes script, max_attempts and base_delay. The script maps a record id to the answers the server gives, in order, each time that record is POSTed. Each answer is [status, retry_after]. When a record's answers run out, the server returns [201, 0]. Status 0 means the connection dropped, so there's no response and its retry_after is ignored.load(records) takes the parsed body of a GET, a list of objects. Put each one in a map keyed by its "id", skip any record whose id is missing or isn't a non-empty string, and let a later copy of an id replace an earlier one. Return how many records the map holds.upload() POSTs each pending record in id order and returns a dict from id to outcome. A 2xx is "ok" and 409 is "exists". Status 0, 429, 500, 502, 503 and 504 are retried, up to max_attempts tries in total, and running out gives "gave up". Any other status is "rejected" with no retry.Before each retry, wait
retry_after seconds when it's above zero, else base_delay * 2 ** (attempt - 1), where attempt counts the tries so far. waited() returns the total seconds waited. A later upload() sends only records with no outcome yet or whose last outcome was "gave up", starting their attempts again from one. Loading a new copy of an id that already has a final outcome doesn't send it again.- Uploader({"b2": [[503, 0], [503, 0]]}, 4, 1)
- load([{"id": "b2", "title": "Bug"}, {"id": "a1", "title": "Docs"}, {"title": "Draft"}])→ 2
- upload()→ {"a1":"ok","b2":"ok"}
- waited()→ 3
The record with no id is skipped. b2 fails twice with 503, so the client waits 1 second, then 2, and the third try gets the default 201.
Keep the loaded records in a dict and the outcomes in another. One helper sends a single record in a loop of attempts, catching the connection error, and returns as soon as the outcome is final.
Upload Records With Retries and Backoff
Click "Run" to execute your code
Build a REST API service live
The September 2026 senior candidate was told one session would be building a REST API HTTP service, with the resource left open. The version here is something like that round, built around a small issues API: create, read, list with a filter, update and delete, each with the status code a client would expect.
The service is a single handle(method, path, body) method that returns [status, body]. That's the shape a real framework calls into, minus the socket. Write it this way in the room and you can test every route in milliseconds, then mount it on a real server in a few lines if asked.
Issues REST Service With Status Codes
Problem
IssueService with one method, handle(method, path, body), that returns [status, response_body]. Each issue is a dict with an id, a title and a state, kept in memory. Ids start at 1 and are never reused, even after a delete.POST /issues with a body holding a non-empty "title" creates an open issue and returns 201 with it. Every error response is a dict with one key, error, holding a message. A missing or blank title returns 400 with the message title is required. GET /issues returns 200 with every issue in id order, and GET /issues?state=open (or closed) filters by state.GET /issues/{id} returns 200 with the issue. PATCH /issues/{id} may set "title" and "state". A blank title gives the 400 above. A state other than open or closed gives 400 with the message state must be open or closed, and changes nothing. DELETE /issues/{id} returns 204 with a null body.An id that isn't a stored issue returns 404 with the message
not found, and so does any path outside /issues and /issues/{id}. Any other method on those two paths returns 405 with the message method not allowed. The method is checked before the id, so PUT /issues/99 is a 405 even when issue 99 doesn't exist.- IssueService()
- handle("POST", "/issues", {"title": "Login page 500s"})→ [201,{"id":1,"title":"Login page 500s","state":"open"}]
- handle("GET", "/issues/1", null)→ [200,{"id":1,"title":"Login page 500s","state":"open"}]
- handle("GET", "/issues/2", null)→ [404,{"error":"not found"}]
The create returns 201 with the new issue. Issue 2 doesn't exist, so the second read is a 404.
Split the path on "?" and "/" first. One segment is the collection route and two segments is the item route. Route on the method inside each, and let small helpers handle create, list and update.
Issues REST Service With Status Codes
Click "Run" to execute your code
Testing the service you built
Candidates who took GitHub's older take-home say the tests they wrote were graded alongside the code. Bring that habit into the live round. Because the service is a function of method, path and body, a test is three lines with no server to start. Write one test per status code, starting with the edges.
def test_create_then_read(): service = IssueService() status, issue = service.handle("POST", "/issues", {"title": "Bug"}) assert status == 201 and issue["state"] == "open" assert service.handle("GET", "/issues/" + str(issue["id"]), None)[0] == 200def test_bad_state_changes_nothing(): service = IssueService() service.handle("POST", "/issues", {"title": "Bug"}) assert service.handle("PATCH", "/issues/1", {"state": "done", "title": "New"})[0] == 400 assert service.handle("GET", "/issues/1", None)[1]["title"] == "Bug"The client gets the same treatment. Since all network access goes through _post, a test swaps in a fake that fails on a schedule and checks the outcome and the total wait, the way the problem 1 tests do. If the interviewer asks how you'd test against the real server, say you'd keep a handful of end-to-end checks and run everything else against the fake.
http.server, or Flask if allowed, can call handle from a request handler in a dozen lines. Do it last, once the routing and status codes are tested.Common questions
What is the HTTP round in the GitHub coding interview?
It's one of the two technical rounds on many 2025-2026 interview days, next to Battleship. You either write a client that calls an API, parses the result and retries failures, or you build a small REST service. When it's a design-only discussion, it's closer to an API design round.
Which language should I use?
Candidates generally pick their own. A 2021 candidate did this round in the editor and language of their choice. Use the language whose HTTP library you know without looking it up. In Python that's requests for a client and http.server or Flask for a service.
Can I look things up during the round?
Searching the web was allowed in several 2021 and 2022 live rounds. GitHub hasn't stated a policy on AI assistants. Ask your recruiter before the day.
Is this the same as the GitHub take-home?
No. The long-running take-home, seen from 2018 to 2024, was a data storage API you built alone and submitted as a pull request. Some teams still use a take-home with a follow-up round. The take-home follow-up covers the current shape, and Older Practice Problems works the classic storage API.
Key Takeaways
- ✓On many 2025-2026 GitHub interview days, the other technical round is about HTTP: call an API or build one.
- ✓Retry dropped connections, 429 and 5xx with exponential backoff. Never retry a 400, and honor Retry-After.
- ✓In a live REST service, put 201, 204, 400, 404 and 405 each in the right place, and test every one.
- ✓Write the service as one handler function so every route is testable without a network.
GitHub interview guideKnow what GitHub asks before you walk in.
20 coding · 3 system design · 31 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.