1. Mid-level

    What is the N+1 problem in the Django ORM and how do you solve it with select_related and prefetch_related?

    N+1 happens when you fetch a list of objects with one query and then an extra query runs for each object when its relation is accessed. select_related solves it for ForeignKey and OneToOne relations via a JOIN, and prefetch_related for multi-valued relations via one second query joined in Python.

    Read the full explanation
  2. Mid-level

    How does a request travel through Django from the middleware to the view?

    The WSGI or ASGI server receives the request, which passes through the middleware chain in the order set in MIDDLEWARE, then the URL resolver matches the path to a view, and the response returns through the middleware in reverse order.

    Read the full explanation
  3. Mid-level

    How does the Depends system work in FastAPI, and when do you use async def or def for routes?

    Depends resolves dependencies (database connection, current user, settings) per request and passes them to the route, and supports nested dependencies and cleanup through yield. Use async def when everything inside is asynchronous, and def for blocking code because FastAPI runs it in a threadpool.

    Read the full explanation
  4. Mid-level

    How does Pydantic v2 validate data, and what is the difference between lax and strict mode?

    Pydantic converts incoming data into a typed model and validates it per the type hints and constraints, and raises a ValidationError with all errors together. In the default lax mode it converts compatible values (such as "42" to int), and in strict mode it rejects any type that does not match exactly.

    Read the full explanation
  5. Senior

    How does the Session work in SQLAlchemy 2.0 and why should its scope be limited to one request?

    The Session applies the Unit of Work and Identity Map patterns: it tracks loaded and modified objects and writes them all at flush or commit inside a transaction. A session should live for a single request or task only because it is not thread-safe and holds state.

    Read the full explanation
  6. Mid-level

    What is the difference between WSGI and ASGI, and how does Flask manage the request context?

    WSGI is a synchronous standard in which each worker handles one request at a time, while ASGI is an asynchronous standard that supports thousands of connections and WebSockets inside an event loop. Flask provides request and g as proxies bound to the current request context through context locals.

    Read the full explanation