Stateful vs stateless
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 · 8 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 big a session store do 2 million concurrent users need?

      What do 1 KB JWTs cost at 50,000 requests a second?

        How many socket gateways for 10 million concurrent users?

          Build-up · 5 steps

          Move the state out of the app

          Start with sessions in each instance’s memory behind a sticky balancer. Kill one, then move the state somewhere built for it.

          Step 1 of 5

          Sessions in memory

          Each instance keeps its users’ sessions in its own memory, so a sticky balancer must send every user back to the same instance.

          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

            “Sessions live in app memory behind sticky load balancing. A big sale is coming and autoscaling will add instances. What do you change?”

            Your move. Pick an approach:

          2. Deep dive 2 of 4

            Interviewer

            “Your mobile login uses JWTs. Security wants logout and bans to take effect quickly. What do you do?”

            Your move. Pick an approach:

          3. Deep dive 3 of 4

            Interviewer

            “You’re building a WhatsApp-style chat for 10 million concurrent users. Where does the state live?”

            Your move. Pick an approach:

          4. Deep dive 4 of 4

            Interviewer

            “Your API’s rate limiter counts requests in each instance’s memory. You scale from 1 instance to 10. What happens?”

            Your move. Pick an approach: