APIs with FastAPI · Chapter 26 of 26

Interview round

By the end of this chapter you have answered five timed questions from across the lab, each a small DakiyaGo API that a teammate got wrong: a route FastAPI never reaches, a response that leaks a secret, an update that loses data, a token check that checks nothing, and a server that freezes while it waits. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Production
  • 5 tasks
  • FastAPI
  • In the all labs plan

The first 2 chapters of APIs with FastAPI are free. This one comes with the all labs plan.

Why you need this

DakiyaGo is hiring a second backend engineer before the festive rush, and Aman runs the interview. "I do not ask people to recite FastAPI's API. I give them a small app that is broken in a way I have seen in production, ten minutes, and a terminal. I listen for two things: do they know what happens on the wire, and do they measure before they guess." Devika liked it enough to make it the last chapter: every engineer who finishes this lab can sit Aman's round.

Each question uses one idea from an earlier chapter, with no hand-holding: the file tells you the incident and shows the teammate's code, the check tries the edges. The ideas are below, as a refresher and as what an interviewer listens for. The fixes are not.

What you build: 5 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1 · interview question

    Interview: route_order.py, the route nobody reaches

    Time yourself: 10 minutes. Make an app over /workspace/data/parcels.json with GET /parcels/summary answering {"count": ..., "by_status": {...}} (how many parcels, and how many have each status that appears) and GET /parcels/{awb} answering the parcel as the file has it, or 404. The teammate's version, in the file, answers 404 "No parcel summary" for the summary.

    The interviewer will ask: why did the summary answer 404, and how does FastAPI choose between two routes that both match?

  2. Task 2 · interview question

    Interview: leaky.py, a response that leaks

    Time yourself: 10 minutes. GET /merchants/{merchant_id} answers a merchant from /workspace/data/merchants.json with exactly id, name, city and plan, or 404; never its api_key. The teammate returned the dictionary from the file. Removing the key by hand is not enough: the route must declare what it sends, so /openapi.json documents exactly those four fields.

    The interviewer will ask: what else might be in that dictionary next year, and what stops it going out?

  3. Task 3 · interview question

    Interview: patch.py, the update that loses data

    Time yourself: 10 minutes. PATCH /parcels/{awb} on the parcels from /workspace/data/parcels.json (kept in memory) takes weight_grams (more than 0, at most 30000) and cod_amount (0 or more), both optional, changes only the fields the client sent, and answers the whole parcel; an unknown AWB is 404. The teammate's version kept only the values that were truthy, so a COD amount of 0 never arrives; the version before it wiped every field not sent.

    The check sends a weight alone, then cod_amount 0, then an empty body. The interviewer will ask: how does the server tell "not sent" from "sent as nothing"?

  4. Task 4 · interview question

    Interview: forged.py, a token check that checks nothing

    Time yourself: 10 minutes. GET /me reads a bearer token (Authorization: Bearer ...) and answers {"merchant_id": <the token's sub>}. Tokens are HS256 JWTs signed with the secret in the environment variable JWT_SECRET, and must carry exp. The teammate decoded tokens without verifying them.

    A token signed with another secret, an expired one, one with alg none, one whose payload was edited, one with no exp, a token that is not a JWT, and no token at all must each answer 401. The interviewer will ask: what does a JWT protect, and what does it not?

  5. Task 5 · interview question

    Interview: frozen.py, the server that froze

    Time yourself: 10 minutes. GET /labels/{awb} waits 2 seconds (it stands for the label printer service, keep the wait) and answers {"awb": ..., "label": "https://labels.dakiyago.test/<awb>.pdf"}; GET /health answers {"status": "ok"}. The teammate's version froze the whole server while a label rendered.

    The check runs it with uvicorn, asks for three labels at once and times GET /health in the middle: health must answer within half a second, and the three labels within about 2 seconds together. The interviewer will ask: what did time.sleep do to every other request?

What you will learn

  • How to work a timed question: reproduce, explain, fix, prove.
  • Five ideas again, at interview depth: route order (chapter 2), response models (4), partial updates (6), tokens (13) and the event loop (15).

More in Production

Build "Interview round" yourself

DakiyaGo, a Jaipur courier startup, takes bookings on WhatsApp. Merchants want an API, and you build it. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of APIs with FastAPI are free. This one comes with the all labs plan.