KatInterview

Design a Resilient AI Chat Service with Streaming and Failover

System DesignModel answer
MediumModel answerSystem Designreal-timemessagingerror-handling

Last updated

Build a customer-facing chat platform powered by a third-party LLM, handling streaming responses, network interruptions, and provider outages gracefully.

You're designing a real-time chat platform for customer support. Customers visit a company's website or mobile app and interact with an AI assistant. The assistant's responses come from a third-party large language model API that your platform calls.

Your interviewer wants you to focus on three areas:

  1. The complete request flow: trace a customer's message from their device through your infrastructure to the LLM provider and back, identifying every component and decision point.

  2. Pub/sub architecture: explain where message brokering fits, which components publish and subscribe, and how messages route when the customer's WebSocket connection lives on a different server than the one generating the reply.

  3. Failure scenarios: this is the core evaluation. Detail your approach when the LLM provider degrades (slow responses, partial failures, or a streamed reply that cuts off mid-sentence) and when the customer's network drops. Cover server-side logic, client-side behavior, and recovery.

Scope and Assumptions

  • The LLM provider is external and unreliable: it may be slow, return errors, time out, or stop streaming partway through.
  • You control the infrastructure between the customer and the provider.
  • Make reasonable assumptions about scale, latency targets, and feature scope. State them clearly.

Questions to Consider

  • Should responses stream token-by-token to the customer, or arrive complete?
  • Can a customer open the same conversation on multiple devices simultaneously?
  • Does the assistant only answer questions, or does it also execute actions like order lookups or refunds?
  • How long is chat history retained, and who else accesses it (analytics, compliance, human agent escalation)?
  • Is there a human handoff path, and if so, how does the transition work?

Hints

Hint 1

Think about how you'll identify and order messages within a conversation, especially when requests are retried or connections fail.

Hint 2

Consider what partial success means for a streamed LLM response—how do you decide whether to show it to the customer or discard it?

Hint 3

Pub/sub should decouple connection handling from AI processing; sketch the topics and the guarantees you need for each.