Backend
36 bites tagged Backend — interview questions with model answers, and 60-second explainers.
What are startup and shutdown events in FastAPI?
Tests app lifespan hooks and resource lifecycle. Startup creates DB pools before traffic arrives; shutdown closes them after the last request. These decorators are deprecated; prefer lifespan context managers. Red flag: per-request middleware.
How do you define a WebSocket endpoint in FastAPI?
Import WebSocket, use @app.websocket, await accept, receive_text, then send_text. async endpoint wiring and the accept-receive-send lifecycle. forgetting accept or treating it like a standard HTTP route.
Frontend on localhost:3000 gets errors calling FastAPI on localhost:8000. Name and fix?
This tests whether different ports mean different origins, causing CORS errors. A strong answer names CORS, notes ports are distinct origins, and outlines using CORSMiddleware with allow_origins.
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.
How to apply a dependency to only one FastAPI router?
Pass dependencies=[Depends(auth)] to APIRouter for /users, omit it for /items, include both. router-level dependency injection in FastAPI. repeating Depends() on every route or using middleware.
How do you include a router in your main FastAPI app?
Create APIRouter in another file, import it into main.py, then call app.include_router(router). knowledge of the APIRouter wiring pattern. rewriting endpoints manually in main.py rather than using include_router.
How would you implement a dependency requiring multi-source parameters?
Tests if you know FastAPI resolves dependency params like endpoint params. Great answers annotate each parameter with its source inside the dependency so FastAPI injects them independently. Red flag: manually parsing Request or merging values in the endpoint.
Describe the data model and backend logic for a daily login bonus.
This tests streak state machines and calendar edge cases. A strong answer stores last_login_utc and streak_count, uses UTC day buckets, resolves timezones per user tz, and needs no leap-year logic. Naive 24-hour windows break during DST shifts.
The N+1 Query Problem
N+1 means fetching one record, then looping to query its relations one by one. It explodes latency in ORM code that looks innocent, turning a page load into hundreds of round-trips. The fix is eager loading, yet developers often miss it until production melts.
How would you track which headline wins in an A/B test?
Tests end-to-end experiment instrumentation across the stack. Outline: deterministically bucket users, serve variant A or B, emit click events, and aggregate by variant.
How do you implement a CTA A/B test and attribute conversions?
This tests experiment architecture from bucketing to attribution. A strong answer covers: stable user bucketing, server or client-side rendering, and conversion events tagged with experiment and variant IDs.
Design a system to A/B test headlines for a single article URL
Hash users for sticky variants; store separately; emit events; compute CTR. controlled experiment design with user bucketing and attribution. client-side randomization without stickiness or event tracking.
How do you build a performant visualization for millions of time-series points?
Tests end-to-end data reduction: backend bucket downsampling like LTTB preserves visual shape, frontend uses level-of-detail rendering and viewport culling. Red flag: naive every-Nth sampling that drops peaks or sending raw millions to the browser.
Strategy for Visualizing Millions of Time-Series Points
Tests your strategy for balancing performance and visual fidelity with large datasets. Propose backend downsampling with an algorithm like LTTB to preserve peaks, then discuss multi-resolution data fetching on the frontend.
What validation checks would you implement for an email field?
Tests your understanding of practical validation vs. theoretical purity. A great answer prioritizes user experience, uses simple syntax checks (like a single '@'), and relies on sending a verification email as the ultimate test.
Visualize Millions of Time-Series Data Points
Tests your ability to handle large datasets by combining backend downsampling (like LTTB) with frontend multi-resolution fetching and canvas rendering. A red flag is suggesting naive sampling (every Nth point) or focusing only on frontend libraries.
Next.js Route Handlers: One File, Multiple Methods
Think of a Next.js Route Handler file as a dedicated API endpoint. You handle different HTTP requests by exporting functions named `GET`, `POST`, `DELETE`, etc. Use them to build API routes for form submissions or to fetch data for client-side components.
Route Handlers: Your Next.js App's API Endpoints
Route Handlers are lightweight API endpoints built into your Next.js app. Use them to serve JSON or handle form posts. The footgun is confusing them with Server Components; Route Handlers return data, not rendered UI.
Layered Architecture: Separating API from Business Logic
A layered architecture separates your API into distinct jobs: routing, controlling, and serving. This keeps code maintainable, like an organized toolbox. It's crucial for growing FastAPI apps.
The 'ws' Library: WebSockets for Node.js Servers
The `ws` library is the standard for adding WebSocket servers to Node.js for real-time features like chat or live data feeds. It provides both server and client APIs for backend-to-backend communication.
Node.js perf_hooks: A High-Precision Stopwatch for Your App
The `perf_hooks` module is a high-precision stopwatch for your Node.js code, offering nanosecond accuracy. Use it to benchmark async operations or HTTP request durations.
Never Trust User Input: The Validation Mindset
Treat all incoming data as hostile until proven otherwise. Input validation ensures only properly formed data enters your system, protecting against errors and attacks. It applies to user forms, APIs, and partner feeds.
API Versioning: Managing Change Without Breaking Clients
API versioning lets you evolve an API without breaking existing clients. It's essential for public APIs or services with multiple frontends that can't update in lockstep. The footgun is delaying versioning, forcing a painful migration on early users.
Express Middleware: Intercepting Requests Before Your Route Handler
Express middleware is like a bouncer for your routes, running code before your main handler. Use it for logging, authentication, or parsing request bodies. The biggest footgun is forgetting to call `next()` or send a response, which leaves requests hanging.
Get Backend bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.