Skip to content
RED SAGSkills
mediumAI Engineer (LLM & Generative AI) interview question

How would you implement streaming LLM responses in a web app, and what problems do you need to handle?

What the interviewer wants to hear

  • Use server-sent events or a streaming HTTP response from the backend
  • Keep the API key on the server and proxy the stream
  • Handle partial tool-call arguments by buffering until complete
  • Handle client disconnects and cancel upstream work
  • Validate or moderate content that is shown before it is complete

Model answer

The browser calls my backend, never the provider directly, so the key stays secret. The backend opens a streaming request to the model and forwards text deltas to the client, usually as server-sent events, and the UI appends them as they arrive. This mainly cuts time to first token, which is what users feel. There are several details to handle. Tool-call arguments stream as JSON fragments, so I buffer them per call and parse only when complete. If the user closes the tab, I cancel the upstream request to stop paying for tokens. Errors can happen mid-stream, so the UI needs a clear failure state and retry. Since text is shown before it is finished, any structured output must be validated at the end, and for sensitive apps I run moderation in chunks.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium AI Engineer (LLM & Generative AI) questions