Start by clarifying requirements and constraints, then outline the architecture with clear separation of concerns (router, service, model layers). Walk through the implementation details for each layer, emphasizing production-ready aspects like validation, error handling, and testability. Conclude by discussing trade-offs and potential improvements.
Pro tip: Demonstrate production-readiness by mentioning observability (logging, metrics) and graceful degradation, and explicitly state assumptions you make about the summarization model (e.g., mock or external API) to keep the focus on API design.
Ask clarifying questions about expected load, summarization model (local vs external), storage persistence, and authentication. State your assumptions to scope the solution.
Define the POST /summarize endpoint with Pydantic models for request (text, optional parameters) and response (summary, request_id). Include error responses and status codes.
Describe the router layer (handles HTTP, validation), service layer (business logic, calls summarization model), and model layer (Pydantic schemas, in-memory storage). Explain how dependencies are injected.
Walk through code for each layer: router uses service, service uses a summarizer (mock or real) and stores request/response in memory, models define schemas and storage structure.
Discuss error handling, logging, testing, and scalability. Mention trade-offs of in-memory storage and how to evolve to a database or external service.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.