| 1 | socket | accepts connections on one address and port | Uvicorn; bound once and shared by every worker | nothing; it only accepts connections | “Address already in use” at startup, or clients refused |
|---|
| 2 | HTTP parser | turns bytes into a method, path, headers and body | each connection, inside Uvicorn | that the bytes are valid HTTP | a request rejected before your app logs anything |
|---|
| 3 | event loop | runs every request of one worker on one thread | the worker process | nothing; it runs whichever request is ready | every request slow at once: something blocks the loop |
|---|
| 4 | ASGI interface | the one call between server and app: scope, receive, send | the line between Uvicorn and the app | that the reply starts before its body is sent | “Expected ASGI message 'http.response.start'” in the log |
|---|
| 5 | router | sends each request to the first route that fully matches | the app, holding its routes in order | the path, then the method | a 404 for a path you defined: an earlier route caught it |
|---|
| 6 | Request and Response | wrap the scope; send the status, headers and body | each endpoint call | nothing; they only carry the data | a header lookup that never matches: names arrive lowercased |
|---|
| 7 | ServerErrorMiddleware | turns an unhandled exception into a plain 500 | the outermost layer of the app | nothing; it catches what every other layer missed | a plain-text 500 and a traceback in Uvicorn’s log |
|---|
| 8 | your middleware | runs your code around every request | inside ServerErrorMiddleware, in list order | whatever you write, such as allowed CORS origins | a browser CORS error while the same call works from curl |
|---|
| 9 | ExceptionMiddleware | turns an HTTPException into its status and body | just outside the router | which handler matches the exception | “Caught handled exception, but response already started.” |
|---|
| 10 | lifespan | runs setup before the first request and cleanup after the last | the app, once per worker process | nothing; it opens and closes shared resources | “Application startup failed. Exiting.” and no server |
|---|
| 11 | Pydantic models | check data against type hints and turn it back into JSON | the route handler, for inputs and outputs | types, ranges and required fields | a ValidationError listing every bad field |
|---|
| 12 | route handler | reads the signature, validates every input, calls the endpoint | each path operation, inside the router | that every parameter passes its Pydantic check | a 422 with a detail list, and your endpoint never runs |
|---|
| 13 | endpoint | your function for one path and method | its route | your business rules | the HTTPException you raise, such as 404 “Book not found” |
|---|
| 14 | dependencies | run shared setup and cleanup before the endpoint | parameters declared with Depends() | whatever they check, such as the API key | a 401 from the key check, or a connection closed too early |
|---|
| 15 | response model | filters and serializes what the endpoint returns | the endpoint’s return annotation | that the return value fits the model | a 500 with ResponseValidationError in the log |
|---|
| 16 | OpenAPI and /docs | describe every route and let people try them | /openapi.json, /docs and /redoc on the app | nothing; it only describes the routes | a blank /docs page: the CDN is blocked |
|---|
| 17 | thread pool | runs def endpoints and dependencies off the loop thread | each worker, 40 threads by default | nothing; it runs what it is given | def endpoints waiting once 40 calls are already running |
|---|
| 18 | background tasks | run work after the reply has been sent | the response | nothing; they run once, in order | an email never sent after the worker restarted |
|---|
| 19 | supervisor and workers | runs several copies of the app and replaces dead ones | the main Uvicorn process | that each worker answers its ping within 5 seconds | “Child process [pid] died” in the log |
|---|
| · | TestClient | calls the app as a function in tests | your test code | nothing; it sends what the test asks | lifespan never ran: the client was not used in a with block |
|---|
| · | proxy headers | take the client address and scheme from a trusted proxy | each connection | that the sender is listed in forwarded-allow-ips | every client logged with the load balancer’s address |
|---|
| · | load balancer | spreads customer traffic over servers | in front of the socket | nothing that Uvicorn sees | all traffic on one server, or the wrong client address |
|---|
| · | reloader | restarts the server when a .py file changes | --reload, in development only | changes to Python files | --workers ignored, and restarts in production |
|---|