Skip to main content

Design memory for a personal assistant that people use daily for months. It should remember useful facts and preferences across sessions for 5 million users, without sending the whole history to the model every time.

System design · Pro 1

Short answer

Clarify what is worth remembering and the privacy rules. Use layers: recent turns in the context window, a rolling summary of the session, and a long-term store of extracted facts and preferences per user, retrieved by relevance. Handle updates and contradictions, let users view and delete memories, and evaluate recall on long conversation tests.

Deeper answer

Requirements: what should persist (preferences, ongoing projects, key facts), what must not (sensitive data without consent), how users control it, and the token budget per request.

Design: three layers. Short-term: the last few turns, word for word. Session: a rolling summary that replaces older turns when the conversation gets long. Long-term: after a session, a background job extracts facts and preferences, each with a source, a timestamp and a type, and writes them to a per-user store. At the start of a request, the system retrieves the few memories relevant to the current message, using embeddings plus recency, and adds a small profile of stable preferences. Writing needs rules: update or replace a fact when it changes, instead of keeping both versions.

Trade-offs: saving more improves recall but adds noise, cost and privacy risk, so be selective. Risks: stale or wrong memories repeated with confidence, and injected text saved as a fact. Give users a page to view, edit and delete memories. Measure with long test conversations that ask about earlier facts, including changed ones, and track tokens per request.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

Agent memory

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.