Bugpit

Lessons › Core concepts

Forget the user between requests

Each server keeps its users' logins in its own memory. When one crashes, everyone on it is logged out, and a new server can't help anyone who logged in elsewhere. 5,000 req/s arrive.

Play this level

Free with an account. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

A stateless server keeps nothing about a user between requests. Any server can answer any request, so you can add, remove or lose servers freely.

The state still has to live somewhere. Put sessions in a shared cache such as Redis, or in a signed token the browser sends with every request.

Sticky sessions send each user back to the same server. They hide the problem until that server dies, and they spread load unevenly.

What you have to achieve

5,000 requests a second at the busiest hour, 10% of them writes.

What you learn

Your servers now forget everyone between requests, so losing one costs nothing but a little capacity. That's what makes adding and removing servers safe.

Check yourself

What makes a server stateless?

Show the answer

It keeps nothing about a user between requests. Stateless means any server can answer any request, because nothing it needs is stuck in one machine's memory.

Where should login sessions live so that any server can read them?

Show the answer

In a shared cache, or a signed token the browser sends. A shared store or a signed token lets every server check the session, so losing a server logs nobody out.

What's the catch with sticky sessions?

Show the answer

When that server dies, its users lose their session. Sticky sessions keep state on one server. They work until it dies, and they also leave some servers busier than others.

Try it yourself

More in Core concepts

← How a request travels Pick the right key →