Skip to course content
Free FastAPI backend course

FastAPI for AI Backend Development

Module 12 Activity

Scenario

Make the boundaries you do not control fail in ways your callers can act on.

What you build

Per-request sessions, mapped boundary failures, timeouts everywhere and bounded retries.

Steps

  1. Make the database session a per-request dependency using yield and finally, and prove every session opened is closed.
  2. Map every boundary exception to a specific status. Confirm none reaches the client as a 500.
  3. Set an explicit timeout on every outbound call, shorter than any gateway in front of you.
  4. Bound your retries, add jitter, and confirm no 4xx is retried.
  5. Confine every query to the repository layer and confirm services import no driver.
  6. Test one service with a fake repository and no database at all.

Evidence to hand in

Review checklist