Skip to content
All paths
Intermediate → AdvancedBackend

FastAPI with Python for AI Backends

Build a document question-and-answer service step by step: a typed async API, tenant-scoped data in PostgreSQL, a model gateway, durable ingestion, retrieval with citations, streamed answers, tests, deployment and operations. Modules 1–2 are beginner FastAPI, modules 3–6 are intermediate backend work, and modules 7–10 cover advanced testing, operations and security. You should already know Python functions, type hints and imports, basic Git, and basic HTTP and SQL; Python from Zero and SQL & PostgreSQL cover those. Everything runs locally with a fake model, so no paid API key is needed.

What you will be able to do

  • Build a typed async FastAPI service with stable request, response and error contracts
  • Persist tenant-scoped data in PostgreSQL with migrations, auth and Redis quotas
  • Wire model calls, ingestion jobs and pgvector retrieval with citations behind one gateway
  • Stream answers to a browser over SSE and handle cancellation and slow clients
  • Test, deploy, observe and secure the service, and recover from failures on purpose

Roadmap

Bar length shows each module's share of study time.

  1. 1

    HTTP, Python and ASGI

    Beginner. How a request reaches your code, your first FastAPI service, and when async helps or hurts. Prerequisites: Python basics and HTTP basics.

    7h 30m3 topics
    Not started
    Show topics
  2. 2

    Contracts and application wiring

    Beginner. Pydantic models, dependency injection, lifespan and error contracts that clients can rely on.

    8h 30m3 topics
    Not started
    Show topics
    Module resources:Pydantic docs ↗
  3. 3

    Application data and access control

    Intermediate. PostgreSQL with async sessions and migrations, authentication with tenant isolation, and Redis caching and quotas.

    11h3 topics
    Not started
    Show topics
  4. 4

    Inference and AI request orchestration

    Intermediate. One interface for model calls, resilience against provider failures, and validated structured output and tool use.

    9h 30m3 topics
    Not started
    Show topics
  5. 5

    Ingest, index and retrieve

    Intermediate. Accept uploads, run a durable ingestion worker, and retrieve tenant-filtered chunks with citations from pgvector.

    11h 30m3 topics
    Not started
    Show topics
    Module resources:pgvector ↗
  6. 6

    Connect web clients and live responses

    Intermediate. Connect a Next.js client, stream answers over server-sent events, and handle disconnects and slow streams.

    9h 30m3 topics
    Not started
    Show topics
  7. 7

    Test correctness and AI quality

    Advanced. Route and dependency tests, retrieval and answer evaluation, and failure drills with local stubs.

    10h 30m3 topics
    Not started
    Show topics
  8. 8

    Ship and observe the backend

    Advanced. Run the full stack in containers, trace requests end to end, and size and scale the service.

    11h3 topics
    Not started
    Show topics
  9. 9

    Secure a multi-tenant AI API

    Advanced. Treat retrieved text and model output as untrusted data, and manage secrets, retention and deletion everywhere data lives.

    6h 30m2 topics
    Not started
    Show topics
  10. 10

    Capstone: document Q&A service

    Advanced. Design, build and release a multi-tenant document Q&A service with a deterministic fake model.

    21h3 topics
    Not started
    Show topics
    • Write the architecture, API and event contracts, data model, failure paths and evaluation fixtures.

      • Draw the request and ingestion diagrams
      • Specify the HTTP and event contract
      • Design the data model
      • List supported failure paths
      • Prepare fixtures for two tenants
    • Build upload, ingestion, polling, tenant-aware retrieval, streamed chat with citations and a minimal UI on a fake model.

      • Build upload and ingestion
      • Add polling and job status
      • Implement tenant-aware retrieval
      • Stream chat with citations
      • Add a minimal UI and the fake model
    • Run tests and evals, demonstrate a failure and recovery, and deploy or document deployment with a teardown plan.

      • Run tests and the eval set
      • Demonstrate a failure and recovery
      • Capture a redacted trace
      • Write the migration and rollback checklist
      • Deploy or document with teardown