Real-time connections
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 · 9 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.

    A million clients poll every 5 s. What does that cost?

      How many gateways for 10 million concurrent users?

        A gateway with 100,000 sockets dies. How fast should clients return?

          Build-up · 6 steps

          Open a WebSocket, frame by frame

          One HTTP request turns a TCP connection into a two-way pipe. Follow it from the upgrade to a clean close.

          Step 1 of 6

          Ask to upgrade

          It starts as one ordinary HTTP/1.1 GET with Upgrade: websocket, a random 16-byte key and, from browsers, an Origin the server should check.

          4 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 4

            Interviewer

            “Ten million viewers follow the same live score, and a couple of seconds’ lag is fine. How do you deliver it?”

            Your move. Pick an approach:

          2. Deep dive 2 of 4

            Interviewer

            “Your assistant streams an LLM’s answer token by token, and each request carries a JSON body. How do you stream it?”

            Your move. Pick an approach:

          3. Deep dive 3 of 4

            Interviewer

            “Ravi’s app sometimes misses messages. His gateway blipped during a Redis pub/sub publish, or his socket died mid-write. What do you change?”

            Your move. Pick an approach:

          4. Deep dive 4 of 4

            Interviewer

            “A gateway holding 100,000 sockets crashes. How should its clients reconnect?”

            Assume the rest of the pool accepts 10,000 new connections a second. Each reconnect costs TLS, auth, re-subscription and a catch-up query.

            Your move. Pick an approach:

          Build-up · 7 steps

          Follow Asha’s message to Ravi’s phone

          Asha and Ravi hold sockets on different gateways. Follow her message through the fleet, and see where it’s stored so nothing is lost.

          Step 1 of 7

          Two sockets, two gateways

          Asha’s socket landed on Gateway A when it opened, Ravi’s on Gateway B, and each stays put for hours. Asha writes a frame on hers.