Skip to content
tezvyn:

⚙️Backend Dev

Backend engineering, APIs, and databases

529 bites

Test yourself: Top 30 intermediate Backend Dev interview questionsMultiple choice, with the correct answer and why it is correct on every question. Free, no sign-in.

Intermediate everything in Backend Dev, page 11

Why synchronous DB libraries block async FastAPI endpoints and correct SQLAlchemy usage
intermediate2 min read

Why synchronous DB libraries block async FastAPI endpoints and correct SQLAlchemy usage

This tests event loop blocking: sync DB calls in async def halt all requests. Answer: sync drivers block the loop despite releasing the GIL; use asyncpg with SQLAlchemy create_async_engine and AsyncSession. Red flag: recommending run_in_executor as default.

How do you use FastAPI dependency injection for database sessions?
intermediate2 min read

How do you use FastAPI dependency injection for database sessions?

Build a generator dependency that yields a session and closes it after; inject via Depends(get_db).

When should you use asyncio.Lock over threading.Lock?
intermediate2 min read

When should you use asyncio.Lock over threading.Lock?

This tests cooperative multitasking knowledge: asyncio.Lock yields to the event loop via await, while threading.Lock blocks the OS thread and freezes the loop. A red flag is claiming threading.Lock works because locks are universal.

Explain the asyncio event loop and cooperative multitasking
intermediate2 min read

Explain the asyncio event loop and cooperative multitasking

Tests if you view the event loop as a single-threaded orchestrator, not magic parallelism. Strong answers note it runs tasks and callbacks, manages a ready queue, and yields control at await. Red flag: calling it multithreading or parallel execution.

How do you safely execute blocking code from an async function
intermediate2 min read

How do you safely execute blocking code from an async function

Tests whether you know how to prevent event loop blocking by offloading sync work. Name asyncio.to_thread or run_in_executor, explain ThreadPoolExecutor scheduling, and note when processes beat threads.

How do you apply a common path prefix across FastAPI routers?
intermediate2 min read

How do you apply a common path prefix across FastAPI routers?

Tests whether you know APIRouter decouples routes from path prefixes. Use relative paths in APIRouter, then mount with app.include_router(router, prefix="/api/v1"). This keeps modules reusable. Red flag: hardcoding the full absolute path in every decorator.

intermediate2 min read

Manage dev, staging, and prod configs in a large FastAPI app

This tests separating environment config from code with pydantic-settings and env vars. A strong answer covers .env files for local dev, per-environment validation, and secret injection for prod. Red flags are hardcoded values or scattered conditionals.

intermediate2 min read

How to apply a dependency to only one FastAPI router?

Pass dependencies=[Depends(auth)] to APIRouter for /users, omit it for /items, include both.

intermediate2 min read

How does FastAPI cache dependencies within a single request?

Tests if you know FastAPI caches a dependency after the first call in a request and reuses it across the tree. A strong answer covers default use_cache=True, request-scoped lifetime, and disabling it.

intermediate2 min read

How does FastAPI execute setup and teardown in nested yield dependencies?

It tests FastAPI's dependency injection lifecycle and stack-like teardown for nested yield dependencies. Setup runs top-down; teardown runs bottom-up after the response. A red flag is claiming teardown order is arbitrary or follows garbage collection.

How do you use a Python class as a FastAPI dependency?
intermediate2 min read

How do you use a Python class as a FastAPI dependency?

It tests whether you understand FastAPI DI beyond functions and when stateful encapsulation wins. Explain that Depends takes callable classes, centralizing setup and shared state in __init__. Red flag: claiming classes are pure syntactic sugar.

intermediate2 min read

How would you override a FastAPI dependency during testing?

Tests your grasp of FastAPI's dependency override mechanism. A strong answer mentions app.dependency_overrides, notes that sub-dependencies are bypassed, and stresses clearing overrides after each test.

intermediate2 min read

How do you set a custom header and cookie in FastAPI?

Tests FastAPI temporal Response injection and merge behavior. Strong answer: inject Response, set headers via response.headers, cookies via set_cookie, then return the payload normally.

intermediate2 min read

How do you create a reusable current-user dependency in FastAPI?

Tests DRY auth with FastAPI Depends. Answer: create get_current_user that Depends on OAuth2PasswordBearer, verifies token, returns User model, inject into routes. Red flag: middleware or manual header parsing in each endpoint.

intermediate2 min read

Implement a FastAPI file upload endpoint with form data

Tests FastAPI multipart literacy. A strong answer names python-multipart, uses Annotated[UploadFile, File()] for the image, and Annotated[str, Form()] for user_id.

Model an Order with a nested Product list in Pydantic
intermediate2 min read

Model an Order with a nested Product list in Pydantic

It tests Pydantic nested model composition. Define Product as BaseModel, then Order with products: list[Product]; Pydantic recursively coerces each dict and raises ValidationError on failure. A red flag is insisting on manual iteration.

How do you prevent password_hash from appearing in a FastAPI response?
intermediate2 min read

How do you prevent password_hash from appearing in a FastAPI response?

Tests FastAPI response filtering and the security practice of separating DB schemas from API contracts. A strong answer proposes a dedicated output model omitting the field, then cites response_model_exclude. Red flag: manual dict deletion or monkey-patching.

Implement a custom validator for a single Pydantic model field
intermediate2 min read

Implement a custom validator for a single Pydantic model field

Use @field_validator as a classmethod, raise ValueError on failure, return the value.

Enforce positive price and SKU format using Pydantic Field without custom validators
intermediate1 min read

Enforce positive price and SKU format using Pydantic Field without custom validators

Use Field(gt=0) for price and Field(pattern=r'^ITEM-\d{5}$') for SKU; mention Annotated.

intermediate2 min read

What standard and code elements power FastAPI's auto-generated API docs?

Tests whether you know FastAPI uses the OpenAPI standard and extracts metadata from Python type hints, Pydantic models, decorators, and docstrings to build interactive docs. Red flag: claiming you must manually maintain a separate schema file.

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles