Slack / Discord
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 11 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    How many messages are sent, and pages read, each second?

      How much disk does a year of messages need?

        How many WebSockets at peak, on how many gateways?

          How much fan-out does a server with a million online need?

            Build-up · 6 steps

            Build the high-level design

            One functional requirement at a time, ending with a platform that works for servers of a few thousand people before any scaling.

            Step 1 of 6

            Send and receive in real time

            Store first, push second. The API checks permissions, assigns a Snowflake ID and writes once; the guild process that owns the server sends one copy per gateway, for online sessions allowed to see the channel.

            6 interview moments

            You’re the candidate

            The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

            1. Deep dive 1 of 6

              Interviewer

              “One server has more than a million people online, and its process is comfortable at 20,000. How do you fan out each message?”

              Your move. Pick an approach:

            2. Deep dive 2 of 6

              Interviewer

              “Trillions of messages, kept for ever, and an @everyone sends hundreds of thousands to one channel’s newest page. How do you store them?”

              Your move. Pick an approach:

            3. Deep dive 3 of 6

              Interviewer

              “A gateway is redeployed and millions of clients drop at once. How do they catch up without knocking the system over?”

              Your move. Pick an approach:

            4. Deep dive 4 of 6

              Interviewer

              “Every sidebar shows unread state for every channel, and an @everyone hits a 10-million-member server. How do you track unread and mentions?”

              Your move. Pick an approach:

            5. Deep dive 5 of 6

              Interviewer

              “One customer is an enterprise of tens of thousands, beside thousands of tiny workspaces. How do you shard so it can’t hurt them?”

              Your move. Pick an approach:

            Build-up · 9 steps

            Follow one message through it

            Writes go through the API to the store and out through guild servers; everything transient stays in memory, and search and push hang off the side.

            Step 1 of 9

            Connect

            The client opens a WebSocket to the nearest gateway and identifies, or resumes with its session ID and last sequence number. Its start-up snapshot is slim, and its sessions in big servers start passive.