Skip to the page

Python and its frameworks · 22 concepts

Python web: Django, FastAPI and Celery

Building and running Python web services as interviews ask it: Django and DRF, FastAPI, Flask, Celery, data access, security and production.

Asked in these mock interviews

Part 1 · 5 concepts

Django and DRF

  1. 01

    A request inside Django, and writing middleware

    The server hands the request to Django, which runs middleware top to bottom, resolves the URL, runs the view and sends the response back up through the middleware…

  2. 02

    QuerySets, select_related, prefetch_related and the N+1 problem

    QuerySets are lazy and cache their results. A foreign key read in a loop causes one query per row. select_related joins in SQL, prefetch_related runs one extra query…

  3. 03

    Transactions, race conditions, on_commit and signals

    Two requests can read the same row and both write, so a read-modify-write needs a conditional UPDATE with F(), or a row lock. Work with side effects (email, a Celery…

  4. 04

    DRF serializers, permissions and building an endpoint

    A serializer turns objects into plain data on the way out and validates input on the way in. Object permissions run only for single-object actions, so list endpoints…

  5. 05

    Async views in Django: what they change and what stays synchronous

    Async views help when one request waits on several slow I/O calls. The ORM and drivers underneath are still synchronous, so async does not make simple CRUD faster.

Part 2 · 4 concepts

FastAPI

  1. 06

    What FastAPI is built on, and validating requests with Pydantic

    FastAPI is a thin layer over Starlette (the ASGI toolkit) and Pydantic v2 (validation), run by a server such as Uvicorn. Type hints become validation, documentation and…

  2. 07

    async def or def in FastAPI, and a blocked event loop

    async def endpoints run on the event loop and must never block. Plain def endpoints run in a thread pool of limited size. A slow call in the wrong place stalls the…

  3. 08

    Dependencies, database sessions, JWT login and lifespan

    Depends() builds a tree of callables per request, such as a database session and the current user. Code after yield may run after the response is sent, so commit inside…

  4. 09

    Testing FastAPI, streaming answers and why BackgroundTasks lose work

    Tests override dependencies and use a real database. Streaming uses an async generator with proper disconnect handling. BackgroundTasks run in the same process with no…

Part 3 · 2 concepts

Flask and choosing a framework

  1. 10

    Flask contexts, the app factory and shared state

    Flask gives each request an application context and a request context, held in context-local proxies. Module-level variables are shared by all threads, so per-request…

  2. 11

    Django, FastAPI or Flask, and mixing them

    Choose by the job and the team: Django for admin-heavy and form-heavy apps, FastAPI for async I/O and typed APIs, Flask for small services. Two frameworks on one…

Part 4 · 4 concepts

Celery and background jobs

  1. 12

    How Celery works, and Redis or RabbitMQ as the broker

    The web app publishes a message to a broker, workers consume it, and an optional result backend stores outcomes. When a message is acknowledged decides whether a crash…

  2. 13

    Idempotent tasks, safe retries and long tasks

    A task can run more than once, so it must be safe to repeat. Retry only temporary errors, with backoff and jitter. A task that does a money step and a notification must…

  3. 14

    Beat, chords and tasks that hang

    Only one beat may run for a schedule. Canvas (chain, group, chord) builds workflows but needs care with failures and result size. A hung task holds a worker slot, and…

  4. 15

    Queues, priorities, vendor limits and choosing a task library

    One shared queue lets bulk work delay urgent work. Separate queues and workers, vendor rate limits and an interface of your own make a task system survive a sale. Other…

Part 5 · 4 concepts

Data access and security

  1. 16

    SQLAlchemy sessions, connection pools and async use

    A Session is a unit of work with an identity map. The engine owns a connection pool per process, so the total connections across pods and workers must fit the database…

  2. 17

    Django and Alembic migrations that are safe to deploy

    A migration changes a live database while old and new code run together. Autogenerate cannot see renames, an index can lock a table, and conflicting migration files…

  3. 18

    SQL injection and mass assignment in Django, DRF and FastAPI

    Never let a client choose column names, filter keys or the fields that are saved. Placeholders protect values only. Accept an explicit list of fields and return a…

  4. 19

    CSRF, password hashing, secrets and login throttling

    Cookies need CSRF protection and tokens in headers do not. Passwords are stored as slow salted hashes, secrets live outside the code, and throttling must use a shared…

Part 6 · 3 concepts

Python services in production

  1. 20

    Gunicorn workers, memory growth and Celery worker sizing in containers

    In a container, Python often sees the node's CPUs, not the pod limit, so default worker counts are too high. Worker memory grows from leaks or one big request, and…

  2. 21

    Nginx 502 and 504, proxy settings, static files and debug pages

    Behind a proxy, each layer has its own timeout and its own view of the request. Wrong order of timeouts, a missing forwarded-protocol header or a missing collectstatic…

  3. 22

    Running Django and Celery on Kubernetes, and upgrading Django

    A production setup separates web, workers, one beat, a migration job and the data stores, with a connection budget and observability. Support ends for old Django…

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview