> For the complete documentation index, see [llms.txt](https://dongzeli95s-organization.gitbook.io/swe-interview-handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dongzeli95s-organization.gitbook.io/swe-interview-handbook/system-design/mocks/design-chatgpt.md).

# Design ChatGPT

## Functional Requirement:

1. Create conversation
2. Send message
3. Delete conversation
4. Language preference?
5. Do we support images/attachment?
6. Thumb up/down?
7. Login system? Rate Limiting?
8. How about context window? In the conversation?

## Non-functional Requirement:

1. Low Latency
2. Highly available
3. Scalable

## Scale

10M user/day -> 5 conversations, 4 messages -> 200M messages per day.

200M messages -> 100 bytes -> 20G per day -> 73TB (10 years)

## High Level Design

<img src="https://3949881291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcZwx4sqIBsQr7kP4dTuJ%2Fuploads%2FSLy3MGbRGSDRgbLjjswr%2Ffile.excalidraw.svg?alt=media&amp;token=53b61878-003a-48ae-9cdc-aa8694419991" alt="" class="gitbook-drawing">

## GPT RLHF

### Fine tuning with RL

Proximal Policy Optimization

1. Policy is a language model that takes in a prompt and returns a sequence of text (just probability distributions over text)

<figure><img src="https://3949881291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcZwx4sqIBsQr7kP4dTuJ%2Fuploads%2FlHEk1jsw38ulElrpdwaP%2FScreenshot%202024-02-19%20at%209.24.28%20AM.png?alt=media&amp;token=7b8f0f5f-afdd-45f2-8832-f4702ff2dd1d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3949881291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcZwx4sqIBsQr7kP4dTuJ%2Fuploads%2FKyuRaGyawZN69V5ybxvN%2FScreenshot%202024-02-19%20at%209.25.01%20AM.png?alt=media&amp;token=ddc20ca0-92fe-4bec-abfc-c1da54b11b6c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3949881291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcZwx4sqIBsQr7kP4dTuJ%2Fuploads%2FUCQoMNHCwjs7YSibHD6v%2FScreenshot%202024-02-19%20at%209.26.54%20AM.png?alt=media&amp;token=6c8df95e-7e4e-41e8-8bfa-81d92718b6cd" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3949881291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcZwx4sqIBsQr7kP4dTuJ%2Fuploads%2FG3e8PtVoENKFcd9abs9w%2FScreenshot%202024-02-19%20at%209.19.18%20AM.png?alt=media&amp;token=9e69c110-a259-4349-a55b-7d2ffe9bec71" alt=""><figcaption></figcaption></figure>
