Skip to main content

Design a real-time Chat & AI Streaming Assistant backend

Support 1:1/group chat or persistent AI conversation threads with token streaming, history pagination, and reconnect recovery.

Official Reference

Model Answer & Explanation

Store conversations and messages in Postgres (indexed by conversation_id, created_at DESC for keyset history). For AI chat: POST /messages creates user message + empty/pending assistant run, streams tokens over SSE (backed by Redis Pub/Sub if decoupling worker from gateway), persists final message + token counts on completion, and supports reconnect/resume from last chunk.

Follow-up Interview Question · How do you handle a user refreshing the browser tab mid-stream without losing the generated answer?

Module Context & References

System Design · Widely asked design scenarios The 80/20 classic architecture prompts: requirements, data model, bottlenecks & tradeoffs
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.