What Happens When You Log In, Step by Step

Checks your password without ever storing it, then remembers you with a session cookie so every later page knows who you are.

Loading the interactive diagram…

What Happens When You Log In, Step by Step

Checks your password without ever storing it, then remembers you with a session cookie so every later page knows who you are.

You

Browser
Client · Hypothetical. Someone signing up, logging in, or using the site once logged in.

Front door

Load balancer
Gateway · Hypothetical. The site's public address: decrypts HTTPS and sends each request to the right service.

Services

Auth service
Service · Hypothetical. Creates accounts, checks passwords, and starts and ends sessions.
App API
Service · Hypothetical. The rest of the site: orders, settings, anything that needs to know who you are.

Data

User database
Database · Hypothetical. One row per account: email, password hash, and whether the email is verified.
Session store
Cache · Hypothetical. Remembers which session id belongs to which user, until it expires.

Outside services

Email provider
External · Hypothetical. Sends the "confirm your email" message.

Flow: Sign up

From filling in the form to "check your inbox": the password is hashed and only the hash is saved.

  1. Browser → Load balancer (Email + password). Someone fills in the sign-up form and presses Create account. HTTPS keeps the password unreadable on the way.
  2. Load balancer → Auth service (Sign up ana@…). The load balancer sends sign-up requests to the auth service.
  3. Auth service → User database (Email taken?). The auth service checks that no account uses this email yet.
  4. User database → Auth service (Not taken). The email is free.
  5. Auth service → User database (Save email + hash). It hashes the password with a random salt and saves only the hash. The password itself is thrown away and never written anywhere.
  6. User database → Auth service (User 42 saved). The new account exists, marked as not yet verified.
  7. Auth service → Email provider (Send verify link). It asks the email provider to send a link that proves the person owns this address.
  8. Email provider → Auth service (Accepted). The provider accepts the email for delivery. The auth service doesn't wait for it to arrive.
  9. Auth service → Load balancer (Check your inbox). The auth service answers that the account is created.
  10. Load balancer → Browser (Check your inbox). The browser shows "We've sent you a link".

Flow: Log in

The password is checked against the stored hash, and a new session is started and handed to the browser as a cookie.

  1. Browser → Load balancer (Email + password). Someone types their email and password and presses Log in.
  2. Load balancer → Auth service (Log in ana@…). The load balancer sends it to the auth service.
  3. Auth service → Session store (Locked out?). Before the slow password check, the auth service makes sure this account isn't locked after too many failures (see Wrong password).
  4. Session store → Auth service (No: 0 recent fails). Not locked: carry on.
  5. Auth service → User database (Find ana@…). The auth service looks the account up by email.
  6. User database → Auth service (User 42 + hash). It gets back the user id and the stored hash. It hashes the typed password the same way and compares: they match.
  7. Auth service → Session store (New session s_8f2c). It makes a long random session id that nobody could guess, and stores it pointing to user 42, expiring in 30 days. Any count of failed tries is cleared.
  8. Session store → Auth service (Stored). The session store has it.
  9. Auth service → Load balancer (Set-Cookie: s_8f2c). The answer sets a cookie holding the session id. It's marked HttpOnly, so page scripts can't read it, and Secure, so it only travels over HTTPS.
  10. Load balancer → Browser (Logged in). The browser saves the cookie and shows the account. From now on it sends the cookie with every request to this site.

Flow: Open a page while logged in

How every later request knows who you are: the cookie travels with it, and the app looks the session up.

  1. Browser → Load balancer (GET /orders + cookie). The browser asks for a page and sends the session cookie along automatically.
  2. Load balancer → App API (GET /orders + cookie). The load balancer sends ordinary pages to the app.
  3. App API → Session store (Who is s_8f2c?). The app asks the session store who this session belongs to. No password is involved.
  4. Session store → App API (User 42). The session is known and not expired, so it belongs to user 42. An unknown or expired one would mean "please log in".
  5. App API → Load balancer (Your orders). The app builds the page for user 42 only.
  6. Load balancer → Browser (Your orders). The browser shows the page. This lookup happens on every request, which is why the session store lives in memory.

Flow: Wrong password

A failed login is counted, so repeated guessing gets slowed down, and the answer never says whether the email exists.

  1. Browser → Load balancer (Email + wrong password). Someone types the wrong password.
  2. Load balancer → Auth service (Log in ana@…). The load balancer sends it to the auth service.
  3. Auth service → Session store (Recent fails?). Before doing the slow hash, the auth service checks how many times this account failed lately.
  4. Session store → Auth service (2 in 15 min). Two recent failures: still under the limit of five, so it goes on.
  5. Auth service → User database (Find ana@…). It looks the account up by email.
  6. User database → Auth service (User 42 + hash). It hashes the typed password and compares: no match.
  7. Auth service → Session store (Fails: 3). It counts the failure. After five, this account would have to wait before trying again.
  8. Session store → Auth service (Counted). The counter expires on its own after 15 minutes.
  9. Auth service → Load balancer (Wrong email or password). The answer is deliberately vague. Saying "no such email" would tell an attacker which emails have accounts.
  10. Load balancer → Browser (Wrong email or password). The browser shows the error. No session, no cookie.

Flow: Log out

The session is deleted on the server, so the cookie stops working even if someone copied it.

  1. Browser → Load balancer (Log out + cookie). Someone presses Log out. The cookie travels with the request as always.
  2. Load balancer → Auth service (End s_8f2c). The load balancer sends it to the auth service.
  3. Auth service → Session store (Delete s_8f2c). The auth service deletes the session from the store. This is what really logs you out.
  4. Session store → Auth service (Deleted). The id now points to nobody. Any copy of the cookie is useless.
  5. Auth service → Load balancer (Clear cookie). The answer also tells the browser to forget the cookie.
  6. Load balancer → Browser (Logged out). The browser removes the cookie and shows the login page.

HowItScales is not affiliated with the companies shown. Components marked Assumption or Hypothetical are not confirmed by the company.