from fastapi import FastAPI, UploadFile, Response from fastapi.responses import StreamingResponse from pydantic import BaseModel, field_validator import base64 app = FastAPI() class PdfSchema(BaseModel): filename: str content_type: str data: str # base64 pdf 10мб @app.get("/data", response_model=PdfSchema) async def get_data(): return await service.get_big_data() @app.get("/download") async def download(): with open("big.pdf", "rb") as f: data = f.read() return Response(content=data, media_type="application/pdf") def heavy_pdf_parse(data: bytes) -> dict: # CPU-heavy логика return {"size": len(data)} @app.post("/parse") async def parse(file: UploadFile): content = await file.read() result = heavy_pdf_parse(content) return result @app.get("/users") async def get_users(): users = await repo.get_users() result = [] for u in users: posts = await repo.get_posts(u["id"]) result.append({"user": u, "posts": posts}) return result @app.get("/download-two") async def download_two(): def iterfile(): with open("big.pdf", "rb") as f: yield from f return StreamingResponse(iterfile(), media_type="application/pdf") class service: @staticmethod async def get_big_data(): return { "filename": "file.pdf", "content_type": "application/pdf", "data": base64.b64encode(b"fake").decode(), } class repo: @staticmethod async def get_users(): return [{"id": 1}, {"id": 2}] @staticmethod async def get_posts(user_id: int): return [{"id": 1, "user id": user_id}]
Python
Why are mutexes needed in Python if GIL already guarantees single-threadedness?
Do you have a duty shift? How did you connect when there were problems on the backend?
What data types are there in Python? Tell me about mutable and immutable types.
A microservice started consuming 100% CPU on all 20 cores after a new release. How would you identify the problem?
Why does the quicksort function use the condition len(arr) <= 1?
Find the character that appears consecutively most often in the string.
What is the difference between threads and processes?
Who configured alerts and how does a service degradation turn into an alert?
What is a generator? Why is it needed in Python?
In a FastAPI service with model inference on PyTorch — what is better to choose: ThreadPool or ProcessPool?
What are HTTP status codes? Name the main ones.
What does the process from commit to deployment on the stands look like?
Why does multithreading still work with IO-bound tasks despite the GIL?
How are floating point numbers (float) structured?
Can you describe the main responsibilities and projects you worked on at your previous job?
What is a Dockerfile and what is it used for?
How did you keep the cache consistent in catalog and cart services — when invalidating, how was it organized?
Tell me about decorators and generators. Write a retry decorator with parameters.
What was the basis for determining the intent and where to redirect the user in your bot?